Django model manager use_for_related_fields and ModelAdmin relationships -
I am having trouble managing my model manager properly while using the admin interface. Basically, I have two models Are:
class employee (model. Model): objects = model. EmployeeManager () username = models.CharField (max_length = 45, primary_key = true). . Category Eotm (models.Model): Month date # Model = Model. Datafield () employee = model Faircy (employee). . .
And I have a employee manager
class which overrides the get ()
method, something like this:
Class Employee Manager (models.Manager): use_for_related_fields = True def (self, * logic, ** keywords): Try: return super (employee manager, self). Except self * model (* logic, ** keyword) .DoesNotExist: # If there is no employee matching query, try a LDAP look and create # example model for the result, if any. In fact, the idea is that they have been created with information in the
objects in Active Directory, if they are not present in the database, it is better than my application code But when I tried to create a Django admin page for theemployee Eotm
model, things were not very good, I had aTextInput
with the widgetThe default widget for the ForeignKey
field has changed. Individual users can type a username (asusername
is the primary key). In principle, it should callEmployeeManager.get (username = 'whatever')
, which will either return aemployee
like default manager or create one and It was possible to return it was not already existed The problem is that my manager is not being used.I do not find anything in the DJ ango documentation about using custom
managers
sections and admin site. I was talking about specifying a custom manager for classes forModelAdmin
, but it does not really help because I do not want to change the model represented byModelAdmin
Yes class, but on which it is related.
I do not understand what you are trying to do here, but you You can use a custom form for your EOTM model:
In the theory, it should work, I have not tested it.
Comments
Post a Comment