Scenario: I'm building an order-form. Like every other order-form on the planet, it has separate invoicing shipping addresses. I've just added a "Use billing address" checkbox to let the user save time.
The problem is, the shipping fields are still there. They will fail validation if the user don't enter any shipping address data (like ...
I have a "Villa" Model with lots of descriptive TextFields. For each TextField, I have a copy which will be the Russian translation of the original field, which I'm naming by appending "_ru", for example "long_description" and "long_description_ru". I would like to exclude all the "_ru" fields from my ModelForm, which I thought I would b...
Hello,
I have a Model enought big to be cut in 3 Forms.
I wanted to use FormWizzard to do that and I am wondering, how to save the information from the form to the database?
Everything is from the same model.
Do you have any idea of how to do that ?
...
I have a model not unlike the following:
class Bike(models.Model):
made_at = models.ForeignKey(Factory)
added_on = models.DateField(auto_add_now=True)
All users may work at a number of factories and therefore their user profiles all have a ManyToManyField to Factory.
Now I want to construct a ModelForm for Bike but I want the...
How do I set the value of a field (which is relevant to form, but not based directly on the same model) on a (model) form when it is displayed in the admin?
Here is a simplified version of what I have (my actual app/model/etc is more complicated):
A building has many rooms
A room has many pieces of equipment
Models:
#spaces/model...
I've found a few posts that are similar in nature to this but they haven't been 100% clear so here goes:
In my views I have an add_album view that allows a user to upload an album. What I'd like to do is clean the form (AlbumForm) to check if this album is unique for an artist.
My AlbumForm looks like this:
class AlbumForm(ModelForm)...
..whatdoyoucallitanyway..
I have this model:
class Kaart(models.Model):
name = models.CharField(max_length=200, name="Kaardi peakiri", help_text="Sisesta kaardi pealkiri (maksimum tähemärkide arv on 38)", blank=False, null=False)
url = models.CharField(max_length=200, blank=False, null=False, name="Asukoha URL", help_text="Täis...
I have this:
class OrderForm(ModelForm):
class Meta:
model = Order
exclude = ('number',)
def __init__(self, *args, **kwargs):
super(OrderForm, self).__init__(*args, **kwargs)
if self.initial.get('account', None):
self.fields['customer'].queryset = Customer.objects.filter(account=self....
You have models:
class Order(Model):
date = DateField(editable = False, auto_now_add=True)
status = CharField(max_length = 1, choices = STATUS, default = 'N')
profile = ForeignKey(Profile, related_name = 'orders', blank = True, null = True)
shipping = ForeignKey(Shipping, related_name = 'orders', blank = True, null = True)
address ...
I've added a custom field to a ModelForm for use in the admin:
class MyModel(models.Model):
name = models.CharField(max_length=64)
...etc...
class MyModelAdminForm(forms.ModelForm):
dynamicfield = forms.IntegerField()
def __init__(self, *args, **kwargs):
super(MyModelAdminForm, self).__init__(*args, **kwargs)
...
And i have a simple modelform for Package
from models import Package
from django import forms
class PackageForm(forms.ModelForm):
class Meta:
model= Package
fields= ['name', 'version', 'url', 'description', 'arch', 'dependancies', 'conflicts', 'file']
How can i ask the modelform to check, within validation, if the file extens...
Consider the following models and form:
class Pizza(models.Model):
name = models.CharField(max_length=50)
class Topping(models.Model):
name = models.CharField(max_length=50)
ison = models.ManyToManyField(Pizza, blank=True)
class ToppingForm(forms.ModelForm):
class Meta:
model = Topping
When you view the Toppi...
Hello,
Is there a way in Django to group some fields from a ModelForm? For example, if there's a model with fields like: age, gender, dob, q1, q2, q3 and a form is created based in such Model, can I group the fields like: info_fields = (age, gender, dob) and response_fields = (q1, q2, q3). This would be helpful to display all fields in ...
I want to learn how can I add to template to my ModelForm i'm newbie. Below you can see my models.py, url.py and views.py:
My model.py looks like that:
from django.db import models
from django.forms import ModelForm
from django.contrib.auth.models import User
class Yazilar(models.Model):
yazi = models.CharField(max_length=200)...
Could anyone please explain to me similarities and differences of Django's forms.Form & forms.ModelForm? I've used Django for 4 days, so excuse me if I don't know basic things. Thanks in advance!
...
The Django docs only list examples for overriding save() and delete(). However, I'd like to define some extra processing for my models only when they are created. For anyone familiar with Rails, it would be the equivalent to creating a :before_create filter. Is this possible?
...
Hello,
With Django models, I want to achieve this:
class Foo(models.Model):
name = models.CharField(max_length=50)
#wrapping the save function, including extra tasks
def save(self, *args, **kwargs):
super(Foo, self).save(*args, **kwargs)
if extra_param:
...do task 1
else:
...
I have 3 models with various fields in each. For 2 of the models, I'm fine with using a generic form (through Django's create_object) to request data. I wrote a function that accepts the model name and sends the user to the generic form
url(r'^add_(?P<modelname>\w+)/$', generic_add),
def generic_add(request, modelname):
mdlnm_mod...
Ok, so I'm fairly new to Django, but have been reading both the online django book and the djangoproject documentation, but I can't seem to figure this error out:
I've got an 'Orders' model:
class Orders(models.Model):
client_id = models.ForeignKey(Client)
order_date = models.DateField(auto_now_add = True)
due_date = models...
I have a model form that contains a DecimalField() with max_digits set to 5. How do I display this field this way:
<input type"text" size="5" maxlength="5" />
...