You are not logged in.

Change Language:

Freelancer? Consultant? Check out: WorkTrail - Time Tracking made easy
Board » General Category » General Discussion » Want To Make This Update Work

Page: Previous 1 2 3 Next

Perhaps I understand better, you want to allow to user to enter a personal description inside body field?
In this way you must to update the record and not insert it.

def homey(request):
    #if theres nothing in the field
    if request.method=="POST":
        form=mobForm(request.POST)
        if form.is_valid():
            data=form.cleaned.data
            if mob.objects.filter(user=request.user).count() = 0:
              newmob=mob(
                user=request.user,
                state_province=None,
                body=data['body'],
                date=datetime.datetime.now())
              newmob.save()
            else:
              mob.objects.filter(user=request.user).update(
                body=data['body'])
            return HttpResponseRedirect('/homi/')
        else:
            return render_to_response('home.html',{'mobForm':form},context_instance=RequestContext(request)) # here you must to set 'mobForm':form and not newmob that is an instance
    else:
        form=mobForm() # here put form=  and not newmob=
        return render_to_response('home.html',{'mobForm':form}, context_instance=RequestContext(request))# same problem


To understand if mod exists you can use also get_or_create:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.get_or_create


--- Last Edited by arwa at 2012-02-09 04:42:49 ---

--- Last Edited by arwa at 2012-02-09 04:43:13 ---
I'm getting syntax error:

def homey(request):
#if there's nothing in the field do nothing.
if request. method=="POST":
form =mobForm(request.POST)
if form.is_valid():
data=form.cleaned_data
if mob.objects.filter(user=request.user).count()=0: #here is where the problem is. I tried changing it but still getting syntax error.
newmob=mob(
username=request.user,
state_province=state_province,
body=data['body'],
date=datetime.datetime.now())
newmob.save()
else:
mob.objects.filter(user=request.user).update{
body=data['body']}
return HttpResponseRedirect('/homi/')
else:
return render_to_response('home.html', {'mobForm': form },context_instance=RequestContext(request))
else:
form = mobForm()
return render_to_response('home.html', {'mobForm': form },context_instance=RequestContext(request))
On which row there is the syntax error?
Here:

if mob.objects.filter(user=request.user).count()=0:
:-)
I'm sorry -> double ==
if mob.objects.filter(user=request.user).count()==0:
Bro, you really tried! But I'm still getting "Mob User already exist"

What I actually want to do is to let users post status update. I guess you know how we update or status on Facebook? Do you really get my point?
I really don't know why you have this problem, you must to debug better.
For example you can use Werkzeug -> http://werkzeug.pocoo.org/ with django-command-extensions https://github.com/django-extensions/django-extensions.
If your server is visible from internet give me the url that I probably can understand error on django traceback. Or send me an email with views.py and models.py

TIP: Everty time that I had to give to manage personal profile I use extended django admin profile:
https://docs.djangoproject.com/en/dev/topics/auth/#auth-profiles
One my example: https://www.futurgest.it/registrazione/passo1/
I'm developing in the development area. Localhost. Send me your email address so that I can mail you. Actually, I'm not dealing with profiles, I'm dealing with update of status. You know what bro? Send me your email address, so I will explain what I actually need in MS format to illustrate so that you can grab what I mean. Thanks so much! You're a rare gem :)
If you want to send messages to users you must to use something like this:
1. model with user FK and one with body TextField
2. create a form with these two fields

I this way i don't understand why your user field in Mob class is unique and why you don't give teh possibility to user to choice receiver other user.

#####@#####.### when you send me email i delete this post.

--- Last Edited by arwa at 2012-02-09 07:42:09 ---

Page: Previous 1 2 3 Next





Powered by Sphene Community Tools