I got 2 models
class Category(models.Model):
name = models.CharField(max_length=30, unique=True)
class Post(models.Model):
......
category = models.ForeginKey(Category)
........
And when I create a form, in select box i got options "Category object", but i would like to display name of category, i am sure it's basic,...
In my form I have a following regex field :
code = forms.RegexField(regex=r'^\d{2}[-]\d{3}', max_length=6, widget=forms.TextInput(attrs=attrs_dict), label="Postal code")
how to create clean method for this field checking if the regex requirements are met ? I'd like to have a custom message here, not django's built in (if it gives any)...
In my application I have an extended User model called UserProfile. This user can add up to 4 Friend models. Each added Friend is related 1 to 1 with UserProfile. In my AddFriend form I have a custom cleaning method, for pid field (personal id). This clean_pid should check if the user with given pid is already registered/added as friend ...
In my view for editing friends I'm checking if form is valid, and then save the form. But somehow the data are not updated. Why my updated form is not saved ? It is 100% valid, since I've checked it earlier.
My form :
class FriendForm(forms.ModelForm):
first_name = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxle...
Hi,
I have django ModelForm for model with ManyToManyField. I want to change widget for this field toCheckboxSelectMultiple. Can I do this without overriding a field in a form definition?
I constantly use code similar to this:
class MyModel(ModelForm):
m2m_field = forms.ModelMultipleChoiceField(queryset = SomeModel.objects.all(),
...
I have a form in my Django app (not in admin) that allows staff members to select a user from a dropdown.
forms.ModelChoiceField(queryset = User.objects.filter(is_staff=False), required = False)
The problem is that the dropdown shows users by usernames whereas I'd rather it show their full name from user.get_full_name() and use userna...
Hi,
I'm using modelforms to generate forms.
wiek = models.PositiveIntegerField(verbose_name="Wiek")
Is there a way to assign CSS style to it? I don't want to create html for forms because it is too much work (complex forms). I want to generate them from models, but I want to style it too. How to create seperate CSS for each form?
Than...
I'm trying to create form, for adding new friend/updating existing one. My first solution uses ModelForm, but data from updated form are not saved. Also problem is that my model has CharFields ('code', 'pid'), that I need to validate with regex through my form. If I exclude those fields in Meta, and add them to the FriendForm, when the f...
hi
i have to update an entry in my django model
i have used force_update in save method like this
register = rform.save(commit=False)
register.user = request.user
register.save(register.user,force_update=True)
but it gives me an error
"ValueError at /status/
Cannot force both insert and updating in model saving."
how to solve this...
I'm new to python and to django so this question will probably be easy to solve but I can't get it to work.
Basically I have a model which contains two foreign keys of User type. I'm building a form in which I want to remove one of the choices of a ModelChoiceField based on another field. I want the user to be unable to select himself in...
I have a form for managing users, a ModelForm type. But for two fields I need a RegexField to validate my data. Because of that I needed to override those fields. But now when I open the form in edit mode (when sending instance of my user) I get no data loaded in both fields. How to avoid it ? Should I forget about regex field and create...
Hi guys,
Is there any analog to Django forms (http://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs) in ASP.NET MVC 2?
...
I have found here on stackoverflow a method to extend django's built-in authentication using signals. My base User is defined by 'email' and passwords (so no username there). So I'm trying to modify it to my needs, but I'm geting a validation error for my form. Strange thing is that error is connected to the User.email field and I'm gett...
I have some troublesome form in my django app. Problem is that it doesn't validate. How can I check what is causing the problem ? I've tried the following :
form.data = {dictionary_with_data}
form.is_valid()
False
form._errors
{}
form.errors
{}
Form.non_field_errors()
[]
...
Let's say Form1 inherits after Form2. Form 1 has fields one, two, three. Can I define a method clean_one in Form2 (so clean for field inherited from other form) ?
...
During user registration I'm calling some custom function :
def user_created(sender, user, request, **kwargs):
form = ExtendedRegistrationForm(validateemail=True, request.POST, request.FILES)
When requesting a form I need to give additional bool argument validateemail. This though give me error :
Exception Type: SyntaxError at /
...
I'm calling my form, with additional parameter 'validate :
form = MyForm(request.POST, request.FILES, validate=True)
How should I write form's init method to have access to this parameter inside body of my form (for example in _clean method) ? This is what I came up with :
def __init__(self, *args, **kwargs):
try:
validate...
I have this form class :
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
self.notvalidate = kwargs.pop('notvalidate',False)
super(MyForm, self).__init__(*args, **kwargs)
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,maxlength=75)))
(...)
if not notvalidate: ...
Hello All,
I am working on integration of django application with facebook and i did almost but I want to give an facility to the user to select his/her username after he/she successfully logged in facebook on my django site here is the code :
form for usename :
class RegisterUsernameForm(forms.Form):
username = forms.RegexField(reg...
Hi all,
It's simple - All I want to do is set who answered the question if the question is answered. Can someone please enlighten me on how to set a form value if the question was answered. I know that I could also set this as an initial value but then I have to selectively determine which records were answered. This seemed simpler bu...