Well this is for starters far far away from the django way of solving
this problem. The typical solution would be to do something like
create a user profile that FK's into the User, to check all the data
in a view and then to create the objects. You can see a nice example
of this in James Bennet's Django-Registration app
(http://code.google.com/p/django-registration/ ).
Secondly at the very least you need to call the supers __init__
function, as that will set up the auto created id fields and I assume
various other tidbits that are used by models.Model instances.
Lastly it looks like you aren't use a form instance to sanitize your
user data, pulling data directly from request.POST is dangerous and
should be avoided by passing it through a form object. Making a form
object in this case should be as simple as for =
form_for_model(Paper_UserReg)(request.POST) then you can
form.is_valid() and get cleaned data from the form object by
requesting form.clean_data.
in all this just seems like an ugly hack with very little added value
over simply using a standard model, and checking input (hell making a
function to do that). I don't see any reason to overwrite init here.
~ Anders
On 5/10/07, theju <[EMAIL PROTECTED]> wrote:
>
> I have a class in a model(shown below).
> --------------------------------------------------------------------
> class Paper_UserReg(models.Model):
> def
> __init__(self,username,password,name_of_author,email_of_author,college_name,unique_id=None):
> self.username = username
> self.password = password
> self.name_of_author = name_of_author
> self.email_of_author = email_of_author
> self.college_name = college_name
>
> from uuid import uuid1
> self.unique_id = str(uuid1())[:13]
>
> user =
> User.objects.create_user(self.username,self.email_of_author,self.password)
> return None
>
> class Admin:
> list_display =
> ["name_of_author","college_name","unique_id"]
>
> def __str__(self):
> return self.username
>
> name_of_author = models.CharField(maxlength=50)
> email_of_author = models.EmailField()
> college_name = models.CharField(maxlength=50)
> unique_id = models.CharField(maxlength=13)
> -------------------------------------------------------------------------------------
> and the corresponding view is:
> ------------------------------------------------------------------------------------
> try:
> u =
> Paper_UserReg(request.POST['username'],request.POST['password'],request.POST['name_of_author'],request.POST['email_of_author'],request.POST['college_name'],int(request.P
> OST['phone_of_author']),None)
> # u.save()
> except IntegrityError:
> return render_to_response("user_details_confirmation.html",
> {"user_exists":"User Already Exists"})
> return render_to_response("user_created.html",
> {"user_created":"Congratulations!!! User created."})
>
> ------------------------------------------------------------------------------------
> when i run the application, the user is created (and also able to
> login in the login page created) and i can see this in the admin pages
> whereas the rest of the data ie the name_of_author, phone_of_author
> etc are not saved in the Paper_UserRegs page in the admin dashboard(or
> in the database also). If i remove the comment on u.save() then i get
> an attribute error that says 'Paper_UserReg' object has no attribute
> 'id'.
>
> What should I do so that both the user is created and the rest of the
> fields are also updated in the database?
>
> PS: I could have inherited the User class and created a sub class but
> the necessity was such that i had to indulge in such a bad practice.
>
> Thanking in advance
> Thejaswi Puthraya
> http://thejuhyd.blogspot.com
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---