I wasn't able to find a way to identify the type of a field in a django template. My solution was to create a simple filter to access the field and widget class names. I've included the code below in case it's helpful for someone else.
Is there a better approach?
## agency/tagutils/templatetags/fieldtags.py
##########################...
Suppose my models.py is like so:
class Character(models.Model):
name = models.CharField(max_length=255)
is_the_chosen_one = models.BooleanField()
I want only one of my Character instances to have is_the_chosen_one == True and all others to have is_the_chosen_one == False . How can I best ensure this uniqueness constraint is re...
I need create the following relationship:
One "Rule" can have many users, but one user can be only one rule.
Using ForeignKey and a ModelForm, I get a select box to select just ONE user, but I want to select many users. It's not a ManyToMany relationship because one user never can be more than one rule.
Here are my model definitions:...
I'm totally understanding the documentation on expanding the Comments app in Django, and really would like to stick with the automatic functionality but...
In the current app, I have absolutely no use for an "URL" to be submitted along with a comment.
Being minimally invasive of the default setup, how can I prevent this field from sho...
Hello (please excuse me for my bad english ;) ),
Imagine the classes bellow:
models.py
from django import models
class MyModel(models.Model):
content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
object_id = models.PositiveIntegerField(_('object id'))
content_object = generic.GenericForeignKey('con...
Hi there,
Django has the StackedInline-Feature for the Admin-Backend - is there any equivalent for django.forms? When i define a ForeignField representing a ManyToOne-Relation, it does not show up in generated forms.
...
Hi.
I have a model, called Student, which has some fields, and a OneToOne relationship with user (django.contrib.auth.User).
class Student(models.Model):
phone = models.CharField(max_length = 25 )
birthdate = models.DateField(null=True)
gender = models.CharField(max_length=1,choices = GENDER_CHOICES)
city = models.C...
I have a very simple model:
class Artist(models.Model):
name = models.CharField(max_length=64, unique=False)
band = models.CharField(max_length=64, unique=False)
instrument = models.CharField(max_length=64, unique=False)
def __unicode__ (self):
return self.name
that I'm using as a model form:
from django.forms import ModelForm...
Since I have not found a Related Links app that works with Django 1.0/trunk, I was looking to create my own.
I would like to attach "Related Links" to models in the same generic way that Comments framework or Tags work.
I've looked over the Content Types documentation but can't wrap my head around (nor find much documentation for) ho...
I have a complex form containing an inline formset, which basically has got some text fields and a file upload field. Now, I want to enable the user to create a new record, and within the same step attach several files.
I think there are different options to achieve this, maybe I could write a jQuery-Plugin that clones the formset, do a...
I am creating a form that uses MultipleChoiceField. The values for this field are derived from another model. This method works fine, however, I am noticing (on the production server) that when I add a new item to the model in question (NoticeType), the form does not dynamically update. I have to restart the server for the new item to...
I did a recaptcha integration using the following django snippet
settings.py
RECAPTCHA_PUBLIC_KEY = '<your public key>'
RECAPTCHA_PRIVATE_KEY = '<your private key>'
#widgets.py
from django import forms
from django.utils.safestring import mark_safe
from django.conf import settings
from recaptcha import captcha...
Is there any good articles that explain custom form fields in django, not custom model fields? I couldn't find any through google.
...
Hello - I am using jQuery to do some inline form validation during user registration to prevent form errors after posting by checking to see if:
username is available
email has not already been registered
The idea is to give the user feedback before the form is submitted to prevent frustration. The code is at the bottom.
Question...
Simply, I write:
# forms.py
class NoteForm(ModelForm):
def __init__(self, *args, **kwargs):
super(NoteForm, self).__init__(*args, **kwargs)
#add attributes to html-field-tag:
self.fields['content'].widget.attrs['rows'] = 3
self.fields['title'].widget.attrs['size'] = 20
class Meta:
model = Note
fields = ('title'...
I'm rather new to Django and I'm using Django 1.0.
I have this:
forms.py:
class MyForm(forms.Form):
extra_cheeze = forms.BooleanField(required=False,
initial=False,
label='Extra cheeze')
views.py:
def order_something(request):
form = MyForm(request.PO...
SelectDateWidget is very convenient but it normally seems to return dates in the format "%Y-%m-%d". It doesn't take a format parameter and doesn't have much documentation. Anyone run into this or have an idea how to work around it to get the output of the date into another format? There is this ticket, #6231 saying that there's a fix to ...
In a custom Form, how does one validate a Model's field's uniqueness (i.e., has unique=True set)?
I know that django's ModelForm automatically performs a validate_unique() function that is called within the BaseModelForm's clean() method -- so, when using ModelForm, this will be handled correctly (as it is in the Admin).
However, I a...
I have a custom form to display goals.
Goals are edited inline in a Game.
class GoalForm(forms.ModelForm):
class Meta:
model = Goal
def __init__(self, *args, **kwargs):
super(GoalForm, self).__init__(*args, **kwargs)
self.fields['goal_scorer'].queryset =
Player.objects.filter(gameroster__game=self.instance.g...
I have a model that has a foreign key relation to another. I'd like to have the dropdown that is produced by widget=forms.Select have a default value
...