incorrect column values in django admin

Note to self: if django admin starts acting strange for a certain model class, make sure that you haven't overridden the model's __init__() method with default arguments. This causes the field values in the admin app to be set incorrectly. For instance, the value of the 'id' column gets the value of the 'user_id' column in the admin list.

So DON'T:

def __init__(self, my_arg = None, *args, **kwargs):
self.my_arg = my_arg
super(MyModel, self).__init__(*args, **kwargs)



But DO:

def __init__(self, *args, **kwargs):
if 'my_arg' in kwargs:
self.my_arg = kwargs["my_arg"]
del kwargs['my_arg']
super(MyModel, self).__init__(*args, **kwargs)

Comments

Popular posts from this blog

Handling control characters (escaping) in python for json and mysql

python port sniffer with pcapy and impacket

Django field, form and model validation process