Finding It Hard To Make It Work!

6 views
Skip to first unread message
Message has been deleted

coded kid

unread,
Feb 7, 2012, 7:14:39 PM2/7/12
to Django users
Hello, I want to make the below codes let users update their status in
the Django . And their update should display on the same template. But
it’s not working. E.g when a user type in “To be a hacker is not a
day’s job” in the status textarea and click on update button below the
form. The update should display on the same template for his or her
friends to see. Just like how we post status update on fb.

In models.py
from django.contrib.auth.models import User
from django.forms import ModelForm, Textarea, HiddenInput
from django.db import models



class mob (models.Model):
username=models.ForeignKey(User, unique=True)
state_province=models.CharField(max_length=50)
body=models.TextField(max_length=10000)
date=models.DateTimeField()

def __unicode__(self):
return u"%s - %s - %s - %s" % (self.username,
self.state_province, self.body, self.date)

def get_absolute_url(self):
return "/post/%s/" % unicode(self.id)
def get_author_url(self):
return "/u/%s/p/0" % (self.username)

class mobForm(ModelForm):
class Meta:
model=mob
fields=('body','username','state_province','date')
widgets={
'body':Textarea(attrs={"rows":2, "cols":40}),
'username': (HiddenInput),
'state_province': (HiddenInput),
'date':(HiddenInput),
}


In views.py
from myweb.meekapp.models import mobForm, mob
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from django.http import HttpResponse, Http404
from django.template import RequestContext
from django.http import HttpResponseRedirect

def homey(request):
#if there’s nothing in the field do nothing.
if request. method != "":
return HttpResponseRedirect('/homi/')

newmob=mob()
newmob.username=request.user
newmob.date=datetime.datetime.now()
newmob.body=request.POST['body']
if request.POST['body'] <> '':
newmob.body=body.objects.get(id=request.POST['body'])
newmob.save()
return HttpResponseRedirect('/homi/')
else:
return render_to_response('meek_home.html', {'mobForm':
mobForm },context_instance=RequestContext(request))




in template

{% extends "base_meek.html" %}
{% block body %}
<div class="form">
<form action="." method="post" enctype="multipart/form-data">
<table>
{{ mobForm }}
</table>
<input type="submit" value="Update" />
</form>
{% endblock %}



What am I doing wrong? Would love to hear your opinion.


Babatunde Akinyanmi

unread,
Feb 8, 2012, 4:02:52 AM2/8/12
to django...@googlegroups.com
Use AJAX or asynchronous programming

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

--
Sent from my mobile device

coded kid

unread,
Feb 8, 2012, 4:11:24 AM2/8/12
to Django users
How bro? Don't know Ajax. Can you please put me through? I'm a
Nigerian bro!

On Feb 8, 10:02 am, Babatunde Akinyanmi <tundeba...@gmail.com> wrote:
> Use AJAX or asynchronous programming
>

Thomas Weholt

unread,
Feb 8, 2012, 4:18:43 AM2/8/12
to django...@googlegroups.com
Google "ajax tutorial" or even better just google jquery and take it
from there. There are several tutorials on how to integrate jquery and
django as well.

Thomas

--
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

coded kid

unread,
Feb 8, 2012, 4:24:31 AM2/8/12
to Django users
Thanks bro. Will do. But do you know about a specific Topic I should
learn?
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Thomas Weholt

unread,
Feb 8, 2012, 4:45:22 AM2/8/12
to django...@googlegroups.com
For instance http://webcloud.se/log/AJAX-in-Django-with-jQuery/ -
showing you both the ajax-part using jQuery and integration with
Django.

But seriously, just google ajax jquery and django. You'll get lots of
hits with great stuff. Google is your friend.

Thomas

--

Babatunde Akinyanmi

unread,
Feb 8, 2012, 6:00:49 AM2/8/12
to django...@googlegroups.com
I agree with Thomas. Google ajax tutorials and that should get you
started. Basically what you'd be doing is to create a form where users
type in their "status". The data would be submitted via ajax and if
successful, the status would be appended to the page. A more detailed
explanation wouldn't be appropriate for this group.

Way to go bro

Reply all
Reply to author
Forward
0 new messages