Search Results

Search found 8719 results on 349 pages for 'django views'.

Page 11/349 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Django - Form validation error

    - by Igor G.
    Hello, I have a model like this: class Entity(models.Model): entity_name = models.CharField(max_length=100) entity_id = models.CharField(max_length=30, primary_key=True) entity_parent = models.CharField(max_length=100, null=True) photo_id = models.CharField(max_length=100, null=True) username = models.CharField(max_length=100, null=True) date_matched_on = models.CharField(max_length=100, null=True) status = models.CharField(max_length=30, default="Checked In") def __unicode__(self): return self.entity_name class Meta: app_label = 'match' ordering = ('entity_name','date_matched_on') verbose_name_plural='Entities' I also have a view like this: def photo_match(request): ''' performs an update in the db when a user chooses a photo ''' form = EntityForm(request.POST) form.save() And my EntityForm looks like this: class EntityForm(ModelForm): class Meta: model = Entity My template's form returns a POST back to the view with the following values: {u'username': [u'admin'], u'entity_parent': [u'PERSON'], u'entity_id': [u'152097'], u'photo_id': [u'2200734'], u'entity_name': [u'A.J. McLean'], u'status': [u'Checked Out'], u'date_matched_on': [u'5/20/2010 10:57 AM']} And form.save() throws this error: Exception in photo_match: The Entity could not be changed because the data didn't validate. I have been trying to figure out why this is happening, but cannot pinpoint the exact problem. I can change my Entities in the admin interface just fine. If anybody has a clue about this I would greatly appreciate it! Thanks, Igor

    Read the article

  • Is there an OR filter? - Django

    - by RadiantHex
    Hi folks, is there any way of doing the following Unicorn.objects.or_filter(magical=True).or_filter(unicorn_length=15).or_filter(skin_color='White').or_filter(skin_color='Blue') where or_filter stands for an isolated match I remember using something similar but cannot find the function anymore! Help would be great! Thanks :)

    Read the article

  • How can join two django querysets in one?

    - by diegueus9
    I need order a Queryset by date in desc order, but i need put in the end the objects at the end, I do this: qs1 = Model.objects.exclude(date=None).order_by('-date') qs2 = Model.objects.filter(date=None).order_by('-date') and my list is: l = list(qs1)+list(qs2) There is a more efficiently way for this?

    Read the article

  • Django: Overriding the clean() method in forms - question about raising errors

    - by Monika Sulik
    I've been doing things like this in the clean method: if self.cleaned_data['type'].organized_by != self.cleaned_data['organized_by']: raise forms.ValidationError('The type and organization do not match.') if self.cleaned_data['start'] > self.cleaned_data['end']: raise forms.ValidationError('The start date cannot be later than the end date.') But then that means that the form can only raise one of these errors at a time. Is there a way for the form to raise both of these errors? EDIT #1: Any solutions for the above are great, but would love something that would also work in a scenario like: if self.cleaned_data['type'].organized_by != self.cleaned_data['organized_by']: raise forms.ValidationError('The type and organization do not match.') if self.cleaned_data['start'] > self.cleaned_data['end']: raise forms.ValidationError('The start date cannot be later than the end date.') super(FooAddForm, self).clean() Where FooAddForm is a ModelForm and has unique constraints that might also cause errors. If anyone knows of something like that, that would be great...

    Read the article

  • How to create a UserProfile form in Django with first_name, last_name modifications ?

    - by Natim
    If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it. However, I could not find any help on the django documentation or in the Django Book. When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile fields as well as some User field. But there is no forms.UserProfileForm (yet?) ! How do you do that ?

    Read the article

  • Matching 3 out 5 fields - Django

    - by RadiantHex
    Hi folks, I'm finding this a bit tricky! Maybe someone can help me on this one I have the following model: class Unicorn(models.Model): horn_length = models.IntegerField() skin_color = models.CharField() average_speed = models.IntegerField() magical = models.BooleanField() affinity = models.CharField() I would like to search for all similar unicorns having at least 3 fields in common. Is it too tricky? Or is it doable?

    Read the article

  • Django - testing using large tables of static data

    - by Michael B
    I am using "manage.py test" along with a JSON fixture I created using using 'dumpdata' My problem is that several of the tables in the fixture are very large (for example one containing the names of all cities in the US) which makes running a test incredibly slow. Seeing as several of these tables are never modified by the program (eg - the city names will never need to be modified), it doesn't make much sense to create and tear down these tables for every test run. Is there a better way to be testing this code using this kind of data?

    Read the article

  • Changing models in django results in broken database?

    - by Rhubarb
    I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model: Caught an exception while rendering: no such column: mySite_book.Title

    Read the article

  • Django unique_together error and validation

    - by zubinmehta
    class Votes(models.Model): field1 = models.ForeignKey(Blah1) field2 = models.ForeignKey(Blah2) class Meta: unique_together = (("field1","field2"),) I am using this code as one of my models. Now i wanted to know two things: 1. It doesn't show any error and it saved an entry which wasn't unique together; So is the piece of code correct? 2. How can the unique_together constraint be be validated?

    Read the article

  • Problem in adding custom fields to django-registration

    - by Pankaj Singh
    I tried extending RegistrationFormUniqueEmail class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): first_name = forms.CharField(label=_('First name'), max_length=30,required=True) last_name = forms.CharField(label=_('Last name'), max_length=30, required=True) def save(self, profile_callback=None): new_user = super(CustomRegistrationFormUniqueEmail, self).save(profile_callback=profile_callback) new_user.first_name = self.cleaned_data['first_name'] new_user.last_name = self.cleaned_data['last_name'] return new_user then changing view # form = form_class(data=request.POST, files=request.FILES) form = CustomRegistrationFormUniqueEmail(data=request.POST, files=request.FILES) but still I am seeing default view containg four fields only .. help is needed

    Read the article

  • Making only a part of model field available in Django

    - by Hellnar
    Hello I have a such model: GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female') ) class Profile(models.Model): user = models.ForeignKey(User) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) class FrontPage(models.Model): female = models.ForeignKey(User,related_name="female") male = models.ForeignKey(User,related_name="male") Once I attempt to add a new FrontPage object via the Admin page, I can select "Female" profiles for the male field of FrontPage, how can I restrict that? Thanks

    Read the article

  • Display/Edit fields across tables in a Django Form

    - by jamida
    I have 2 tables/models, which for all practical purposes are the same as the standard Author/Book example, but with the additional restriction that in my application each Author can only write 0 or 1 books. (eg, the ForeignKey field in the Book model is or can be a OneToOneField, and there may be authors who have no corresponding book in the Book table.) I would like to be able to display a form showing multiple books and also show some fields from the corresponding Author table (eg author_name, author_address). I followed the example of the inlineformset and but that doesn't even display the author name in the generated form.

    Read the article

  • Django: testing get query

    - by Brant
    Okay, so I am sick of writing this... res = Something.objects.filter(asdf=something) if res: single = res[0] else: single = None if single: # do some stuff I would much rather be able to do something like this: single = Something.objects.filter(asdf=something) if single: #do some stuff I want to be able to grab a single object without testing the filtered results. In other words, when i know there is either going to be 1 or 0 matching entries, I would like to jump right to that entry, otherwise just get a 'None'. The DoesNotExist error that goes along with .get does not always work so well when trying to compress these queries into a single line. Is there any way to do what I have described?

    Read the article

  • Django aggregation query on related one-to-many objects

    - by parxier
    Here is my simplified model: class Item(models.Model): pass class TrackingPoint(models.Model): item = models.ForeignKey(Item) created = models.DateField() data = models.IntegerField() In many parts of my application I need to retrieve a set of Item's and annotate each item with data field from latest TrackingPoint from each item ordered by created field. For example, instance i1 of class Item has 3 TrackingPoint's: tp1 = TrackingPoint(item=i1, created=date(2010,5,15), data=23) tp2 = TrackingPoint(item=i1, created=date(2010,5,14), data=21) tp3 = TrackingPoint(item=i1, created=date(2010,5,12), data=120) I need a query to retrieve i1 instance annotated with tp1.data field value as tp1 is the latest tracking point ordered by created field. That query should also return Item's that don't have any TrackingPoint's at all. If possible I prefer not to use QuerySet's extra method to do this. That's what I tried so far... and failed :( Item.objects.annotate(max_created=Max('trackingpoint__created'), data=Avg('trackingpoint__data')).filter(trackingpoint__created=F('max_created')) Any ideas?

    Read the article

  • Django RadioButtons with icons and not label?

    - by Asinox
    Hi guy's , i have an app that have 2 fields: company_name and logo, i'm displaying the companies like radiobutton in my Form from Model, but i want to show the logo company instead of the company label (company name) Any idea ? My forms: class RecargaForm(ModelForm): compania = forms.ModelChoiceField(queryset=Compania.objects.all(), initial=0 ,empty_label='None', widget=forms.RadioSelect()) class Meta: model = Recarga Thanks :)

    Read the article

  • django forms in diferent contexts

    - by z3a
    I'm in a middle of a problem, I have a url like /account/login that displays a login form. I need to include this form in another template that have a different url. I tried to use {%include%} but this don't work, the form is not shown. Any one have a clue about this??

    Read the article

  • Django unable to update model

    - by user292652
    i have the following function to override the default save function in a model match def save(self, *args, **kwargs): if self.Match_Status == "F": Team.objects.filter(pk=self.Team_one.id).update(Played=F('Played')+1) Team.objects.filter(pk=self.Team_two.id).update(Played=F('Played')+1) if self.Winner !="": Team.objects.filter(pk=self.Winner.id).update(Win=F('Win')+1, Points=F('Points')+3) else: return if self.Match_Status == "D": Team.objects.filter(pk=self.Team_one.id).update(Played=F('Played')+1, Draw = F('Draw')+1, Points=F('Points')+1) Team.objects.filter(pk=self.Team_two.id).update(Played=F('Played')+1, Draw = F('Draw')+1, Points=F('Points')+1) super(Match, self).save(*args, **kwargs) I am able to save the match model just fine but Team model does not seem to be updating at all and no error is being thrown. am i missing some thing here ?

    Read the article

  • django models objects filter

    - by ha22109
    Hello All, I have a model 'Test' ,in which i have 2 foreignkey models.py class Test(models.Model): id =models.Autofield(primary_key=True) name=models.ForeignKey(model2) login=models.ForeignKey(model1) status=models.CharField(max_length=200) class model1(models.Model): id=models.CharField(primary_key=True) . . is_active=models.IntergerField() class model2(model.Model): id=models.ForeignKey(model1) . . status=model.CharField(max_length=200) When i add object in model 'Test' , if i select certain login then only the objects related to that objects(model2) should be shown in field 'name'.How can i achieve this.THis will be runtime as if i change the login field value the objects in name should also change.

    Read the article

  • How to display total record count against models in django admin

    - by Rog
    Is there a neat way to make the record/object count for a model appear on the main model list in the admin module? I have found techniques for showing counts of related objects within sets in the list_display page (and I can see the total in the pagination section at the bottom of the same), but haven't come across a neat way to show the record count at the model list level.

    Read the article

  • Modify on-the-fly verbose_name in a model field on django admin

    - by PerroVerd
    Hi I have this sample model working with the admin class Author(models.Model): name = models.CharField(_('Text in here'), max_length=100) with verbose_name set as ugettext_lazy 'Text in here', but sometimes, depending on the site_id i want to present a diferent verbose name, so I modified the init in this way def __init__(self, *args, **kwargs): super(Author, self).__init__(*args, **kwargs) #some logic in here self._meta.get_field('name').verbose_name = _('Other text') It works, displaying the 'Other text' instead the 'Text in here'... except for the very first time the author/add view is used. ¿Is it the right way to do it? ¿How can i fix the first time problem? Thanks in advance

    Read the article

  • Django Forms - change the render multiple select widget

    - by John
    Hi, In my model I have a manytomany field mentors = models.ManyToManyField(MentorArea, verbose_name='Areas', blank=True) In my form I want to render this as: drop down box with list of all MentorArea objects which has not been associated with the object. Next to that an add button which will call a javascript function which will add it to the object. Then under that a ul list which has each selected MentorArea object with a x next to it which again calls a javascript function which will remove the MentorArea from the object. I know that to change how an field element is rendered you create a custom widget and override the render function and I have done that to create the add button. class AreaWidget(widgets.Select): def render(self, name, value, attrs=None, choices=()): jquery = u''' <input class="button def" type="button" value="Add" id="Add Area" />''' output = super(AreaWidget, self).render(name, value, attrs, choices) return output + mark_safe(jquery) However I don't know how to list the currently selected ones underneath as a list. Can anyone help me? Also what is the best way to filter down the list so that it only shows MentorArea objects which have not been added? I currently have the field as mentors = forms.ModelMultipleChoiceField(queryset=MentorArea.objects.all(), widget = AreaWidget, required=False) but this shows all mentors no matter if they have been added or not. Thanks

    Read the article

  • Django: How to set default language in admin on login

    - by lazerscience
    I'm saving an user's default language in his user profile and on login I want to set the admin's default language to it. One possibility I was thinking of is using a middleware, but I think if I do it on process_request I will not see an user object there since this is processed AFTER the middleware, so I could only set it after the next request! Any solutions are highly appreciated!

    Read the article

  • Django access data passed to form

    - by realshadow
    Hey, I have got a choiceField in my form, where I display filtered data. To filter the data I need two arguments. The first one is not a problem, because I can take it directly from an object, but the second one is dynamically generated. Here is some code: class GroupAdd(forms.Form): def __init__(self, *args, **kwargs): self.pid = kwargs.pop('parent_id', None) super(GroupAdd, self).__init__(*args, **kwargs) parent_id = forms.IntegerField(widget=forms.HiddenInput) choices = forms.ChoiceField( choices = [ [group.node_id, group.name] for group in Objtree.objects.filter( type_id = ObjtreeTypes.objects.values_list('type_id').filter(name = 'group'), parent_id = 50 ).distinct()] + [[0, 'Add a new one'] ], widget = forms.Select( attrs = { 'id': 'group_select' } ) ) I would like to change the parent_id that is passed into the Objtree.objects.filter. As you can see I tried in the init function, as well with kwargs['initial']['parent_id'] and then calling it with self, but that doesnt work, since its out of scope... it was pretty much my last effort. I need to acccess it either trough the initial parameter or directly trough parent_id field, since it already holds its value (passed trough initial). Any help is appreciated, as I am running out of ideas.

    Read the article

  • Manually listing objects in Django (problem with field ordering)

    - by Chris
    I'm having some trouble figuring out the best/Djangoic way to do this. I'm creating something like an interactive textbook. It has modules, which are more or less like chapters. Each module page needs to list the topics in that module, grouped into sections. My question is how I can ensure that they list in the correct order in the template? Specifically: 1) How to ensure the sections appear in the correct order? 2) How to ensure the topics appear in the correct order in the section? I imagine I could add a field to each model purely for the sake of ordering, but the problem with that is that a topic might appear in different modules, and in whatever section they are in there they would again have to be ordered somehow. I would probably give up and do it all manually were it not for the fact that I need to have the Topic as object in the template (or view) so I can mark it up according to how the user has labeled it. So I suppose my question is really to do with whether I should create the contents pages manually, or whether there is a way of ordering the query results in a way I haven't thought of. Thanks for your help!

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >