django-forms

A question on editing a seach view in Django

Hello I am working in django how to use a search form from Django documents site. Here are some information below. Now, is there a way I can produce a part search for title? For example if I wanted to search for a book called "Apress", But instead of typing the whole word I just wrote "ap" to get Apress. Is there a way how to achieve thi...

Form doesn't accept additional parameters

I was trying to pass an additional parameter to my form, which is anObject to ForeignKey relation. But dunno why form returns __init__() got an unexpected keyword argument 'parent' when I'm pretty sure that it is possible to send additional parameters to form's __init__ (ie here : http://stackoverflow.com/questions/3182262/simple-form-no...

form doesn't allow editing

I have a following form: class PlayForwardPageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PlayForwardPageForm, self).__init__(*args, **kwargs) class Meta: model = PlayForwardPage exclude = ( 'id',) def save(self, *args, **kwargs): post = super(PlayForwardPa...

Why is self.instance not set in clean function for a bound form?

I have a Django 1.1 model with unique_together on the owner and title where owner is foreign key on a user. This constraint is enforced but only after the clean. According to Django docs, I should be able to access self.instance to see non-form field object properties of a model instance. However, I get the error 'JournalForm' obje...

Django database learn itself

Hey guys. I have a system that relies on other models but want to make it a little more open-ended as my users demand a bit more sometimes. currently for arguments sake I have 2 authors in an Author model. john, james When a user adds a book, and the Author is not available, how do I add a other field in the form, that if selected, ...

Why doesn't Django enforce my unique_together constraint as a form.ValidationError instead of throwing an exception?

This is a follow-up to this question. If I don't explicitly check the unique_together constraint in the clean_title() function, django throws an exception: IntegrityError at /journal/journal/4 duplicate key value violates unique constraint "journal_journal_owner_id_key" Request Method: POST Request URL: http://local...

Django friendship in messages compose

Hi. I am using django-friends and django-messages. I have modified my custom compose form to pull the following information, myfriends and also display their fullnames instead of just usernames. One problem I have is that I cannot seem to access myself as a signed in user, to complete the query, I have to hard code it. class MyCompos...

How to add custom control to django admin site?

Hey, I want to add custom buttom to the django admin site, and the users must be administrators, I do not expect you tell me how to do in each step, but please brief write the right approach, if you also can provide some reading URLs, that's gonna be awesome. ...

How to validate django form only when adding not editing

Hi, How could we make the django form to not validate if we are editing, not adding a new record. The code as following : class PageForm(forms.Form): name = forms.CharField(max_length=100,widget=forms.TextInput(attrs={'class':'textInput'})) description = forms.CharField(max_length=300, required=False,widget=forms.TextInput(attrs={'class...

Form loses ability to send POST requests after 2 ajax updates

I have an included object's form: <form method="post" class="object_form" id="event-core-form" action="{% url save_event_core_data event.id %}" enctype="multipart/form-data"> {{ form.as_p }} <p> <input class="object-submit" id="object-data-save" type="submit" value="Save data"> </p> </form> After hitting 'submit' b...

How to render CharField into static text in Django?

Hello All, I started to code in Django quite recently, so maybe my question is a bit wierd. Recently I needed to render the CharField fields from the model into simple static text in html , but I figured out that it seems it's not that simple in this case as I could think, or I am doing something wrong... I have this model: class Tag(...

Excluding a form field, yet adding it back in with clean()

In the django admin, I have an inline that I want to have the viewing user filled in automatically. During the clean function, it fills in the created_by field with request.user. The problem is that since the created_by field is excluded by the form, the value that gets inserted into cleaned_fields gets ignored apparently. How can I do t...