How do I use CSS in Django?
I am creating my application using Django, and am wondering how I can make Django use my CSS file? What settings do I need to do to make Django see the css file? NB: On a local machine ...
I am creating my application using Django, and am wondering how I can make Django use my CSS file? What settings do I need to do to make Django see the css file? NB: On a local machine ...
Say I have the following in my models.py: class Company(models.Model): name = ... class Rate(models.Model): company = models.ForeignKey(Company) name = ... class Client(models.Model): name = ... company = models.ForeignKey(Company) base_rate = models.ForeignKey(Rate) I.e. there are multiple Companies, each having a...
I am hoping to dynamically update a ModelForm's inline Meta class from my view. Although this code seems to update the exclude list in the Meta class, the output from as_p(), as_ul(), etc does not reflect the updated Meta exclude. I assume then that the html is generated when the ModelForm is created not when the as_*() is called. Is th...
I'm trying to validate that a submitted URL doesn't already exist in the database. The relevant parts of the Form class look like this: from django.contrib.sites.models import Site class SignUpForm(forms.Form): # ... Other fields ... url = forms.URLField(label='URL for new site, eg: example.com') def clean_url(self): ...
If I have a Django form such as: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() And I call the as_table() method of an instance of this form, Django will render the fields as the same order as specified above. My question is how does Django ...
I have 2 objects, both from different Model classes, and want to show a form containing some fields from each one. How can I do this? ...
As the title suggests. I want to be able to change the label of a single field in the admin application. I'm aware of the Form.field attribute, but how do I get my Model or ModelAdmin to pass along that information? ...
I have a Client and Groupe Model. A Client can be part of multiple groups. Clients that are part of a group can use its group's free rental rate at anytime but only once. That is where the intermediary model (ClientGroupe) comes in with that extra data. For now, when I try to save the m2m data, it just dies and says I should use the C...
I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views? regards chriss ...
I'm using Django to write a blog app, and I'm trying to implement a hierarchical category structure. Each category has a "parent" ForeignKey pointing back to the same Category model. I want to allow admins to add categories, and I want the interface to allow them to select a category's parent category. However, I want to avoid I'm-my-...
Hello, Is it possible to have a variable number of fields using django forms? The specific application is this: A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The number of pictures will depend on...
Formsets have a .save() method, and the documentation says to save in views like this: if request.method == "POST": formset = BookInlineFormSet(request.POST, request.FILES, instance=author) if formset.is_valid(): formset.save() # Do something. else: formset = BookInlineFormSet(instance=author) I am followin...
I'd prefer my primary key field weren't visible in my edit page. If I make it an AutoField, it isn't rendered in the HTML form. But then the primary key value isn't in my POST data either. Is there a simple way to render the AutoField as a hidden field? ...
I'm trying to build my own custom django form widgets (putting them in widgets.py of my project directory). What should the value "value_from_datadict()" return? Is it returning a string or the actual expected value of the field? I'm building my own version of a split date/time widget using JQuery objects, what should each part of the...
I'm working on an attendance entry form for a band. My idea is to have a section of the form to enter event information for a performance or rehearsal. Here's the model for the event table: class Event(models.Model): event_id = models.AutoField(primary_key=True) date = models.DateField() event_type = models.ForeignKey(Even...
I have two models, Room and Image. Image is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in a way that violates DRY. Was hoping someone who's a little ...
I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so <input type='text' name='relations' value='a' /> <input type='text' name='relations' value='b' /> in cleaned_data i receive only value of second input ('b')...
ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example: http://code.djangoproject.com/ticket/5247#comment:6 My models and form: class Company(models.Model): company_name = models.CharField(max_length=200) class Contact(models.Model): company = models.ForeignK...
I have an Entry. There's a field, brotherEntry, that could point to another Entry. So when I show the form writeEntry, the user can select a brother entry from the list of entries already inserted. However, that list doesn't show all of them, just a few. I can't figure out why is doing that... Any idea? #models.py class Entry(models.Mod...
Problem: A Modeformset needs to include a dictionary of foreign key values in the form to provide context for the user or at least each value as a field or widget. All the advanced formset usage posts don't cover ModelForms w/extra attributes. Is there a way to include an extra dictionary or show only field values and not the name/value ...