Django TypeError int() argument must be a string or a number, not 'QueryDict'

Getting a TypeError when I click submit on my index page

int() argument must be a string or a number, not 'QueryDict'

I want to pass in the user and message variables so that when they submit the message, both user and message get saved in the database. At this moment, I don't see how in my index.html I am supposed to use those variables passed in (user and message) to relay back that information.



Request Method: POST
Request URL:

Django Version: 1.6.1
Python Version: 2.7.2
Installed Applications:
Installed Middleware:

File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Josh\Documents\Message\SimpleMessage\SimpleMessage\" in index
File "C:\Python27\lib\site-packages\django\db\models\" in save
  545.                        force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\django\db\models\" in save_base
  573.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Python27\lib\site-packages\django\db\models\" in _save_table
  635.                                       forced_update)
File "C:\Python27\lib\site-packages\django\db\models\" in _do_update
  665.         filtered = base_qs.filter(pk=pk_val)
File "C:\Python27\lib\site-packages\django\db\models\" in filter
  590.         return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\" in _filter_or_exclude
  608.             clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\" in add_q
  1198.         clause = self._add_q(where_part, used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\" in _add_q
  1232.                     current_negated=current_negated)
File "C:\Python27\lib\site-packages\django\db\models\sql\" in build_filter
  1125.         clause.add(constraint, AND)
File "C:\Python27\lib\site-packages\django\utils\" in add
  104.         data = self._prepare_data(data)
File "C:\Python27\lib\site-packages\django\db\models\sql\" in _prepare_data
  79.             value = obj.prepare(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\sql\" in prepare
  352.             return self.field.get_prep_lookup(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\fields\" in get_prep_lookup
  369.             return self.get_prep_value(value)
File "C:\Python27\lib\site-packages\django\db\models\fields\" in get_prep_value
  613.         return int(value)

Exception Type: TypeError at /
Exception Value: int() argument must be a string or a number, not 'QueryDict'


class User (models.Model):
    name = models.CharField(max_length=20)

    def __unicode__(self):              

class Message (models.Model):
    content = models.TextField(max_length=140)
    user = models.ForeignKey(User)
    time = models.DateTimeField()

    def __unicode__(self):              
        return self.content

def index (request):
    if request.method == 'POST':
        u = User(request.POST)
        m = Message(request.POST)
        return render_to_response('index.html', {
                'user': u,
                'message': m,
                }, RequestContext(request))
        u = User()
        m = Message()
        return render_to_response('index.html', {
                'user': u,
                'message': m,
                }, RequestContext(request))


<form action="{% url 'index' %}" method = "post">
{% csrf_token %}
<input type="text" name="user" id="user" maxlength="20" placeholder = "Username">
<textarea rows="4" cols="35" name="text" maxlength="140" placeholder = "Message goes here"></textarea><br>
<input type="submit" value="Submit">


You directly pass the POST query dict to instruction of Model.

Change it:

u = User(request.POST)


u = User(name=request.POST.get('user'))

And, this:

m = Message(request.POST)


m = Message(content=request.POST.get('text'), user=u)

Also if you want to adding time of message automatically, change this line:

time = models.DateTimeField()


time = models.DateTimeField(auto_now_add=True)

Need Your Help

Where can I bind column cell view controls?

objective-c cocoa

I've been Googling for 3 hours, I can't find where to bind these things for Core Data in this textbook I'm reading. I just want to know where to find out where to bind it. I assume it's in the bind...

Unable to cast NSMutableDictionnary as [String: AnyObject]


I am moving to Swift 2.1 some code that was managing persistency CoreData. Though I get a strange error telling me that I can't cast NSMutableDictionnary to [String: AnyObject] which is something I...