To extend Shawn's answer on your example :) params = {'username': 'admin', 'email': 'x...@xyz.com', 'password': 'xyz123'} # then new_user = User(**params) new_user.save() # or User.objects.create(**params)
On Sun, May 8, 2011 at 1:44 PM, Eiji Kobayashi <itoshinom...@gmail.com>wrote: > Hi! > > Sorry. Another question, please. > > Is it possible to create a model instance using a string parameter? > > Example, I would like to be able to do something like: > > param = "username='admin', email='x...@xyz.com', password='xyz123'" > new_user = User(param) > > Of course this won't work. But is there a similar method? I don't want to > hard type every single fieldname (and the corresponding value) for every > field I'd like to have when instantiating a record for a model. > > Anyone? > > Eiji > > -- > 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. > -- 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.