Re: Not able to use ModelForm

2011-02-20 Thread The_Legend
Daniel thanks man for helping, and noticing problems in that dirty
mess. i am basically very new to django.
I hadn't given a field called address in the form, and + didnt give it
blank=True in the model either so i guess it wasnt working, + what you
said was also true.

thanks a lot, hope u are always there to help ;)

On Feb 20, 7:56 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sunday, February 20, 2011 12:05:12 PM UTC, The_Legend wrote:
>
> > Oh sorry, i thought i wrote, but i guess it didnt convey the message.
>
> > have written a registration form. so it takes data from this form then
> > first creates a user  then i have a model called people in my app
> > called mainapp. so i just need to add data to the database for this
> > model. but i am not able to.
>
> > in this part if i give it like this ---
>
> > dt = people()
> > tform=popform(instance=dt)
> > form = tform(perDict)
> >     if form.is_valid():    -- it says object not callable --
> > tform(perDict) where perDict is dictionary
>
> > and if i give
> > dt = people()
> > form = popform(perDict)
> >     if form.is_valid():    --then it always comesout invalid
>
> Well, there was no way to tell that from the original posting because it
> didn't include any of that code.
>
> This code is very bizarre. You instantiate the form with
> `tform=popform(instance=dt)` and then attempt to call it again with
> `tform(perDict)`. I expect that the `object not callable` exception actually
> happens here, not in the is_valid() call.
>
> The correct way to instantiate a form from a post using an existing model
> instance is to pass both arguments at the same time:
>
>     `tform = popform(perDict, instance=dt)`
>
> Also, you should consider why you need to pre-process the request to get the
> perDict dictionary. It would make more sense to use the same field names in
> the template as in the form.
> --
> DR.

-- 
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.



Re: Not able to use ModelForm

2011-02-20 Thread The_Legend
Oh sorry, i thought i wrote, but i guess it didnt convey the message.

have written a registration form. so it takes data from this form then
first creates a user  then i have a model called people in my app
called mainapp. so i just need to add data to the database for this
model. but i am not able to.

in this part if i give it like this ---

dt = people()
tform=popform(instance=dt)
form = tform(perDict)
if form.is_valid():-- it says object not callable --
tform(perDict) where perDict is dictionary

and if i give
dt = people()
form = popform(perDict)
if form.is_valid():--then it always comesout invalid








On Feb 20, 4:34 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sunday, February 20, 2011 11:26:18 AM UTC, The_Legend wrote:
>
> > i am not able to use model forms to input data for models in database.
>
> I'd get some treatment for that, if I were you.
>
> Seriously, what problem are you having? Are we supposed to guess?
> --
> DR.

-- 
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.



Not able to use ModelForm

2011-02-20 Thread The_Legend
i am not able to use model forms to input data for models in database.

model.py --

gender_list = (('M', 'Male'), ('F', 'Female' ))
class people(models.Model):
userID = models.ForeignKey(User, unique=True)
name = models.CharField('name',max_length=30)
address = models.CharField('address',max_length=50)
enrol_no = models.IntegerField('enrol',max_length=10);
email = models.EmailField()
date_of_birth = models.DateField('birthday')
gender = models.CharField(max_length=1, choices=gender_list)

view.py --

class popform(ModelForm):
class Meta:
model = people

def create_user(request):
message = 'Create New User'
uForm = NewUserForm()
if request.method == 'POST':
if request.POST['submit'] == 'Create':
postDict = request.POST.copy()
uForm = NewUserForm(postDict)
try:
#user object
user = User.objects.create_user(postDict['username'],
postDict['email'],
postDict['password'])
user.last_name = postDict['last']
user.first_name = postDict['first']
user.save()

#people object
perDict = {}
perDict['userID'] = user.id
perDict['name'] = postDict['first']
perDict['email'] = postDict['email']
perDict['gender'] = postDict['gender']
perDict['enrol'] = postDict['enrol_no']
dt = people()
form=popform(instance=dt)
if form.is_valid():
   try:
form.save()
return render_to_response('/login/')
   except:
message = 'Database Error.'
user.delete()
else:
message = 'Form Data Error'
user.delete()
except:
message = 'User creation Error'
return render_to_response('register.html',{
'uForm': uForm,
'message': message })

please need help

Thank you.


-- 
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.



Not able to use CSS in Django templates

2011-02-19 Thread The_Legend
I tried a lot, found another post with same some, but without luck :(

till now ---

project name --- library--- c:\library\

C:\library>dir

Directory of C:\library

02/19/2011  07:29 PM  mainapp
02/19/2011  11:26 AM   557 manage.py
02/19/2011  08:16 PM  media
02/19/2011  08:19 PM 3,537 settings.py
02/19/2011  08:19 PM 2,215 settings.pyc
02/19/2011  07:58 PM  templates
02/19/2011  08:17 PM   832 urls.py
02/19/2011  08:18 PM   655 urls.pyc
02/19/2011  11:26 AM 0 __init__.py
02/19/2011  11:30 AM   120 __init__.pyc


in settings.py i added 

MEDIA_ROOT = 'C:/library/media/'
DOCUMENT_ROOT = 'C:/library/media/'
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/amedia/'


in my urls.py ---

(r'^home/$','library.mainapp.views.display'),
(r'^media/(?P.*)$','django.views.static.serve',
 { 'document_root' : '/media/'} ),

in my html (used as template in django)---

 

but still without luck, please need help urgently

thank you

-- 
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.