O okay I see you what you mean. Vitaly Babiy
On Sat, Feb 28, 2009 at 3:51 PM, Alex Gaynor <alex.gay...@gmail.com> wrote: > > > On Sat, Feb 28, 2009 at 3:47 PM, Vitaly Babiy <vbabi...@gmail.com> wrote: > >> Here is my constructor: >> >> class EmailVerification(models.Model): >> def __init__(self, user, ip, *args, **kargs): >> # Build sha1 for email verification >> sha1 = sha.new("".join([str(user.id), user.email, ip])) >> self.sha = sha1 >> self.user = user >> >> >> Vitaly Babiy >> >> >> On Sat, Feb 28, 2009 at 3:41 PM, Alex Gaynor <alex.gay...@gmail.com>wrote: >> >>> >>> >>> On Sat, Feb 28, 2009 at 3:38 PM, Vitaly Babiy <vbabi...@gmail.com>wrote: >>> >>>> I have a model that I have created a custom consturctor now when I use >>>> it in a test or in loaddata, I get this error: >>>> >>>> vba...@vbabiy-laptop:~/projects/git-projects/howsthedotcom$ ./manage.py >>>> loaddata email_verification >>>> Installing json fixture 'email_verification' from >>>> '/home/vbabiy/projects/git-projects/howsthedotcom/../howsthedotcom/fixtures'. >>>> Problem installing fixture >>>> '/home/vbabiy/projects/git-projects/howsthedotcom/../howsthedotcom/fixtures/email_verification.json': >>>> Traceback (most recent call last): >>>> File >>>> "/usr/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", >>>> line 150, in handle >>>> for obj in objects: >>>> File >>>> "/usr/lib/python2.5/site-packages/django/core/serializers/json.py", line >>>> 41, >>>> in Deserializer >>>> for obj in PythonDeserializer(simplejson.load(stream)): >>>> File >>>> "/usr/lib/python2.5/site-packages/django/core/serializers/python.py", line >>>> 96, in Deserializer >>>> yield base.DeserializedObject(Model(**data), m2m_data) >>>> TypeError: __init__() takes at least 3 non-keyword arguments (1 given) >>>> >>>> >>>> >>>> >>>> Vitaly Babiy >>>> >>>> >>>> >>> You need to create a constructor that has a comptible signature with the >>> default one, Django instantiates models in a number of places and short of >>> going in and hacking up the django source(which will cause it to break for >>> other models) it's not going to magically work with your new signature. If >>> you could provide your modified __init__ we could give some suggestions as >>> to how to make the signature compatible. >>> >>> Alex >>> >>> -- >>> "I disapprove of what you say, but I will defend to the death your right >>> to say it." --Voltaire >>> "The people's good is the highest law."--Cicero >>> >>> >>> >> >> >> > Ok what I would do is something like this: > def __init__(self, *args, **kwargs): > user, ip = kwargs.pop('user', None), kwargs.pop('ip', None) > if user and ip: > kwargs['sha'] = sha.new("".join([str(user.id), user.email, ip])) > kwargs['user'] = user > super(MyModel, self).__init__(*args, **kwargs) > > Which should work for both way of using it, although you need to pass user > and ip as key word arguments and not as positional args. > > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---