django-forms

Django admin site: How does the Add User page works (more fields on edit) ?

I was wondering how they made it possible to display more fields in the User page of the djagno admin site. If you create a new User you only have some basic fields to fill in but if you reopen that user (edit mode) then you see a lot more fields to fill in. Im trying to achieve the same, I had a look at the add_form.html template but I...

How can you manually render a form field with its initial value set?

I'm trying to render a form's fields manually so that my designer colleagues could manipulate the input elements within the HTML instead of struggling in Python source. ie. Instead of declaring form fields like this... {{ form.first_name }} .. I actually do ... <label for="id_first_name">Your name:</label>...

Monkey patching a Django form class?

Given a form class (somewhere deep in your giant Django app).. class ContactForm(forms.Form): name = ... surname = ... And considering you want to add another field to this form without extending or modifying the form class itself, why does not the following approach work? ContactForm.another_field = forms.CharField(...) (...

Django GenericForeignKey Widget: Using the value of one field inside another's widget

I have a GenericForeignKey in an inline on an admin page. Being a GenericFK there are 2 fields involved in it: The ContentType FK and the object_id integer field. The GenericFK can, of course, point to a variety of models and objects, some that have image fields and some that don't. My goal is to customize one of the widgets (it can be e...

How to save form data to different models with one-to-one relationship in Django

This is actually a follow-up to a previous question. A user's profile data is spread over several different models, like so: # Simplified versions, actual classes contain many more fields. class Profile(models.Model): # returned by Django's User.get_profile() user = models.OneToOneField(User) home_address = models.OneToOne...

Adding Multiple Models to inlineformset_factory

I have a model like below. class Content(SimpleModel): title = models.CharField(max_length=255) body = models.TextField() slug = models.SlugField(max_length=50) def __unicode__(self): return self.title class MediumStuff(models.Model): meta_value = models.TextField() meta_key = models.SlugField('Fie...

Change Form Validation for Admin Login in Django

I use a custom auth backend in my django application that allows users to login with ther emails. But when I try to login in the admin I get the message: "usernames cant contain the '@' char" I suppose this error is raised before it reaches the auth backend, so its a form issue, right ? ...

Django Forms validation error - TypeError 'str' object is not callable

so...i've been banging my head on this for a bit. I'm getting the most bizarre error when attempting to validate a form. I pass input to the form wanting to test behavior when the form fails validation, i.e. i expect it to fail validation. i've got this code for a form: class CTAForm(forms.Form): first_name = forms.CharField(...

[Django] Multiple (model)forms, one page, signals: validate on submit, not on edit.

I am generating multple forms on one page using signals like: def send_articleform(sender, form, request, type=None, nid=None, **kwargs): if sender == 'article': if nid == None: if request != None: formset = modelformset_factory(Article, form=ArticleModelForm) form['article...

Django question: An invoice that I want to send to an email

Hello, this is a Django related question. I have an invoice that I have created from a database which displays the information. Now I want to know is if I can send these details to an email address. I have tried looking at this page at http://docs.djangoproject.com/en/dev/topics/email/, but I don't know if I am looking for that. I am ass...

Django show get_full_name() instead or username in model form

Hey guys. I have a model that references a ForeignKey(User) field. When a user selects an item on his form I would like them to be able to see the get_full_name() instead of just the username. class Books(models.Model): author = models.ForeignKey(User) ...

Django: Get Model instance from Form without saving

Let say I have a django ModelForm which I want to edit before saving. For example, Instead of this model_instance = form.save() I would like to do something like this model_instance = form.get_model() model_instance.edit() #say add a new field which is not available on form model_instance.save() ...

How correctly override ModelForm's save() method for a model with tags?

Consider I have defined the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model): title = models.CharField(max_length=100) date = models.DateField() tags = models.ManyToManyField(Tag) and the following model form: class EntryForm(forms.ModelForm): tags = CharField(max...

FK not populating in django form

Hello everyone. I have a small question to ask the community. I am wondering why my foreign key will not show up when I go to my edit form. When I go to edit the information, all my data is populated except for status (which is a foreignkey that points from the status table to project table), which is left with nothing selected. I ...

Django - Form Widgets - Select box - Overriding the style attribute?

I have a Django (1.1) form. One of the fields is CharField with a set number of choices, this is correctly rendered as a <select> box. However the html style attribute for the <select> is set as …style="width: 100px"…. I want to conserve screen space, so I want to change this to style="width: auto", or even just remove the style attribut...

Form uploading files to different server without following

How can I send a file in django to a different server without user being redirected to the server ? So all goes to rewriting this simple php function in django : $filename = 'C:/tmp/myphoto.jpg'; $handler = 'http://www.example.com/upload.php'; $field = 'image'; $res = send_file($filename, $handler, $field); if ($res) { echo 'do...

Checking for duplicates

Hello everyone, I have a small problem. I am trying to check to see if status's value already exists and make sure I do not create another instance of it, but I am having some trouble. Ex. If the project status was once "Quote" I do not want to be able make the status "Quote" again. Right now, I check to make sure if the user select...

Specific Quote Issue

Hey everyone, Here is my problem. I have a model Project, that has a quote field in it. When a new instance of project is created I need to append the last 2 digits of the year plus a hyphen onto the start of the "quote" field. Ex. 2010 = "10-". Im just not quite sure how to start it? As of right now I have hard coded in "10-" in a...

Django- populating an "update/edit" form with an autofield and foreignkey

Hello- I'm new to Django and I'm creating an app to create and display employee data for my company. Currently the model, new employee form, employee table display, login/logout, all works. I am working on editing the current listings. I have hover on row links to pass the pk (employeeid) over the url and the form is populating correctl...

Django update multiple queries

I am building a small app that looks at availability of vehicles and helps a customer book it. in this I am making use of a form wizard that guides the user through the steps. in the backend I am updating all the queries successfully, however I am not quite sure on how to execute one part of it. I have two models, Quote and Vehicle V...