django-forms

Django ModelAdmin - fieldsets ... field 'date' missing from the form

I figured out what the problem was while writing this question. I post it anyway in case it could help someone else. The error: 'FooAdmin.fieldsets[0][1]['fields']' refers to field 'date' that is missing from the form. With the following code: # models.py from django.db import models class Foo(Base): date = models.DateField(auto_...

Django how to modify database records by template

I want to delete the records which i select, and run.html will refresh, how can i do that? Since i use function run in views.py to send records in database, and run need one parameter build which can be got by using run.name, so i think i need to pass "run.name" and "run.id" when i click the submit button. urls.py urlpatterns = pattern...

Best way to do register a user in Django

I'm trying to implement User Registration for my Django app. The book I read mentions UserCreationForm but I need more than just name, password, and email address. I could implement my own user object and use ModelForm I think, but then I lose out on some of the django conveniences for authentication. Finally, I read something about U...

Adding extra fields not working in my django form

I have a model with a custom property class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient = models.ForeignKey(Ingredient) serving_size = models.ForeignKey(ServingSize) quantity = models.IntegerField() order = models.IntegerField() created = models.DateTimeField(auto_now_add = True)...

Django ModelForm validated without submitting

I have a form on my home page. My view for that looks like this: from djangoproject1.authentication import forms from django.http import HttpResponseRedirect from django.shortcuts import render_to_response def main(request): uf = forms.UserForm() upf = forms.UserProfileForm() return render_to_response("authentication/index...

Django form pass parameter from template to view by submit button

I want to pass a parameter, when i click submit button. urls.py urlpatterns = patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^home/$', 'views.home'), (r'^home/(?P<build>[^/]+)/$', 'views.run'), (r'^run/delete/$', 'views.runDelete') ) run.html <form nam...

Django forms request.user

I my model users can create rifles and this rifle is obviously associated with a User. class Gun(ImageModel): user = models.ForeignKey(User) ... ... ... I have another model which is dependent on this and need to make use of the users rifles, but when the user adds a record I only want to display his rifles. mt ...

Django password problems

I'm using a modelform for User like so: class UserForm(forms.ModelForm): class Meta: model = User fields = ('username','password','email',) but the password field shows up as a regular textfield, not a password input. How do I make sure it shows a password field? I tried this: class UserForm(forms.ModelForm): ...

Django clean method throwing KeyError on POST

I'm getting a KeyError for 'password' when I try to submit my form. trace: Request Method: POST Request URL: http://localhost:8000/register/ Django Version: 1.2.1 Python Version: 2.7.0 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'djangoproject1.authentication'] Installed ...

Django error: 'NoneType' object is not subscriptable

It's taking me way to long to make this simple form. Almost there but when I submit I get the NoneType error views.py: from djangoproject1.authentication import forms from django.contrib.auth.models import User from django.http import HttpResponseRedirect from django.shortcuts import render_to_response def main(request): rf = for...

django modelform css class for select

Hi. I am trying to add in a class with the name of autocomplete into one of my select. class MyForm(ModelForm): class Meta: model = MyModel exclude = ['user'] def __init__(self, user, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['specie'].queryset = Specie.objects....

Processing dynamic MultipleChoiceField in django

All the answers I've seen to this so far have confused me. I've made a form that gets built dynamically depending on a parameter passed in, and questions stored in the database. This all works fine (note: it's not a ModelForm, just a Form). Now I'm trying to save the user's responses. How can I iterate over their submitted data so I c...

Form, Model, Model Form

So I can create all the necessary db fields in my models. I can create forms to access these models. And if I create models from forms: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ I cant understand why I have to redefine the Fields like these: class AuthorForm(forms.Form): name = forms.CharField(max_length=100)...

Replace "this field is required" message in django admin

Hi, is there a way to replace the default error message in django admin. I'm using custom widget so I have the form and I was wondering is there something like: field_1 = forms.Charfield(widget=X, error_messge='y') I already tried to add claen_field_1 method but it looks that it is not called when the field is empty. Any ideas will...

How do I include a Django app in my PYTHONPATH?

I want to be able to import things from applications in my project without referring to my project name. My folder structure is like so; I have a project called djangoproject1, and inside I have a folder called apps, and then I have my individual apps in that folder. djangoproject1, apps, and all my applications have an empty "__init__...

Django, restrict access to registration success page.

This is something I've wondered about in a couple of frameworks that I've messed around with. Assuming I don't want to automatically log a user in when they register (I want them to activate) how can I make it so a user can't just visit the "register-success" page? Right now, here's what I have: def register(request): if request....

How to check value transition in Django (django-admin)? (Revisited)

I was wondering about how to control transitions in model data. I found the solution at http://stackoverflow.com/questions/867120/how-to-check-value-transition-in-django-django-admin but when I tried to implement it within my code, something went wrong (I am able to change the status with impunity): Here is the relevant portion of my ...

How to change Django NullBooleanField widget application wide?

I would want to display all NullBooleanFields in my application as radio buttons. What's the best way to do it? Following template or something similar would be ideal. Just to allow rich styling and tone-of-voice different from plain "Yes/No/Unknown". '''<li class="field-%s"> <label class="%s" title="%s">%s</label> <label class...

Get Value Of Selected Option ModelChoiceField

Without using Ajax is there a way to get the value of a selected item. So for example, if I have the below drop down list: <select name="controllers" id="id_controllers"> <option value="" selected="selected">---------</option> <option value="1">http://przemeklach.com/api/firstOrder/przemeksController&lt;/option&gt; <option value="5">ht...

Django Queryset to List conversion => Data loss?

I'm trying to populate a list based on partiular members, but it doesn't seem to be going to plan. user = request.user members = [] userprofile = user.get_profile() if user.is_superuser or user.is_staff: if userprofile.countries.count() == 0: members = Member.objects.all() elif userprofile.countr...