Access to the last object of model inside model itself

2019-01-25 Thread Mohammad Etemaddar
Hello I need the last object of model inside it. for example I have: class Field(models.Model): category = models.ForeignKey(Category, related_name='fields', on_delete= models.CASCADE, default = get_last_factory_field_category()) def get_last_factory_field_category(): return Field.objects.last().c

Re: Access to the last object of model inside model itself

2019-01-25 Thread Jason
This really should be in a custom model manager, and not the model itself. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.

Re: Access to the last object of model inside model itself

2019-01-26 Thread Mohammad Etemaddar
Im not agree. Managers are created for custom query. But here the query is last. I think I got the philosophy. The default value should not be a manager, because the database does not understand it. Maybe I am wrong! -- You received this message because you are subscribed to the Google Groups "

Re: Access to the last object of model inside model itself

2019-01-26 Thread Mohammad Etemaddar
I commented out the default value and then ran the makemigrations again, and then uncommented again and worked. Of course by lambda. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from i