def index(self, request, extra_context=None):
"""
Display the main admin index page, which lists all of the installed
apps that have been registered in this site.
"""
app_list = self.get_app_list(request)
context = {
**self.each_context(request),
'title': self.index_title,
'app_list': app_list,
**(extra_context or {}),
}
request.current_app = self.name
return TemplateResponse(request, self.index_template or
'admin/index.html', context)
def to_representation(self, instance):
response = super().to_representation(instance)
if instance.avatar.name:
response['avatar'] = response['avatar']
else:
response['avatar'] = "http://localhost:8000/media/images/avatar-test.jpg"
return response
zak = Zakaz.objects.get(id=self.zakaz.id)
zak.v_rabote = True
zak.save()
class NaRabotu(Instrument,Material):
zakaz = OneToOneField (Zakaz, on_delete=PROTECT, verbose_name= 'Заказ',related_name="zakaz")
rabotnik = ForeignKey(Rabotnik, on_delete=PROTECT, verbose_name= 'Работник', related_name="rabotnik")
date = DateTimeField(auto_now_add=True,verbose_name= 'Принято к исполнению')
def __str__(self):
return str(self.zakaz) +'==>>' + str(self.zakaz.v_rabote)
def save(self, *args, **kwargs):
print('Привет 1')
print (f"\n self.zakaz.__dict__ === {self.zakaz.__dict__}")
print (f"\n self.zakaz.v_rabote === {self.zakaz.v_rabote}")
print (f"\n self.__dict__ === {self.__dict__}")
self.zakaz.v_rabote = True
print (f"\n self.zakaz.__dict__ === {self.zakaz.__dict__}")
class NaRabotuManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(zakaz__v_rabote=False)
class NaRabotu(Instrument,Material):
object = NaRabotuManager()
zakaz = ForeignKey(Zakaz, on_delete=PROTECT, verbose_name= 'Заказ',related_name="zakaz")
#Забирает только отсортированные Менеджером объекты!!!!
v_zakaz = ForeignKey('self', on_delete=PROTECT, verbose_name= 'Заказ')
rabotnik = ForeignKey(Rabotnik, on_delete=PROTECT, verbose_name= 'Работник', related_name="rabotnik")
date = DateTimeField(auto_now_add=True,verbose_name= 'Принято к исполнению')
v_rabote = models.BooleanField(default=False, db_index=True, verbose_name= 'Заказ в работе')
class Zakaz(models.Model):
pokupatel_name = models.CharField(max_length=150, verbose_name= 'Покупатель')
pokupatel_email = models.EmailField(verbose_name= 'Покупатель email')
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',message=
"Phone number must be entered in the format: '+999999999'. Up to 10 digits allowed.")
pokupatel_phone = models.CharField(validators=[phone_regex], max_length=12, verbose_name= 'Телефон покупателя') # validators should be a list
work = ForeignKey(Usluga, on_delete=PROTECT, verbose_name= 'Вид работы', related_name="work")
date = DateTimeField(auto_now_add=True,verbose_name= 'Дата оформления заказа')
v_rabote = models.BooleanField(default=False, db_index=True, verbose_name= 'Заказ в рабооте')
def __str__(self) :
return "Заказ №" + str(self.id) + " - " + str(self.work)
class Meta:
verbose_name= 'Заказ'
verbose_name_plural= 'Заказы'
class NaRabotu(Instrument,Material):
zakaz = ForeignKey(Zakaz, on_delete=PROTECT, verbose_name= 'Заказ',related_name="zakaz")
rabotnik = ForeignKey(Rabotnik, on_delete=PROTECT, verbose_name= 'Работник', related_name="rabotnik")
date = DateTimeField(auto_now_add=True,verbose_name= 'Принято к исполнению')
def __str__(self):
return str(self.zakaz)
class Meta:
verbose_name= 'В работу'
verbose_name_plural= 'В работу'