python - Django reverse OneToOneField lookup in unicode method -


i have schedule , event models this.

class schedule(models.model):     jan = models.floatfield(default=2.0)     feb = models.floatfield(default=2.0)      def __str__(self):         return 'some boring value'  class event(models.model):     name = models.charfield(max_length=20)     schedule = models.onetoonefield(schedule, null=true, on_delete=models.cascade)      def __str__(self):         return self.name 

in admin view, want add schedule in eventadmin class in collapsed fashion this.

class scheduleadmin(admin.modeladmin):     fieldsets = [     ('schedule', {'fields': ['jan','feb']}),     ]        class eventadmin(admin.modeladmin):     fieldsets = [     ('event', {'fields': ['name',]}),     ('add schedule', {'fields': ['jan','feb'], 'classes': ['collapse']}),     ] 

so when add schedule event, want schedule str method return related event.name field in admin form, instead of 'some boring value' now.

i want assign schedule object once event, instead of form in admin showing list of other schedules other events - have disable add , edit functionality if schedule added event.

i use admin.tabularinline sometimes, , maybe should try using method instead, because not register schedules in admin (which i'm not interested in either) - return error 'schedule has no foreign key event' , have not found way solve reverse lookups in admin yet either.

what correct way proceed?

so when add schedule event, want schedule str method return related event.name field in admin form, instead of 'some boring value' now.

add related_name='event' models.onetoonefield relation, can replace return 'some boring value' return self.event.name.

as for:

i want assign schedule object once event, instead of form in admin showing list of other schedules other events - have disable add , edit functionality if schedule added event.

it's not clear want achieve here.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -