Search Results

Search found 3554 results on 143 pages for 'django modelforms'.

Page 81/143 | < Previous Page | 77 78 79 80 81 82 83 84 85 86 87 88  | Next Page >

  • what is this 'map' mean..in django

    - by zjm1126
    this is the code: def create(request, form_class=MapForm, template_name="maps/create.html"): map_form = form_class(request.POST or None) if map_form.is_valid(): map = map_form.save(commit=False) and the map_form is : class MapForm(forms.ModelForm): slug = forms.SlugField(max_length=20, help_text = _("a short version of the name consisting only of letters, numbers, underscores and hyphens."), #error_message = _("This value must contain only letters, numbers, underscores and hyphens.")) ) def clean_slug(self): if Map.objects.filter(slug__iexact=self.cleaned_data["slug"]).count() > 0: raise forms.ValidationError(_("A Map already exists with that slug.")) return self.cleaned_data["slug"].lower() def clean_name(self): if Map.objects.filter(name__iexact=self.cleaned_data["name"]).count() > 0: raise forms.ValidationError(_("A Map already exists with that name.")) return self.cleaned_data["name"] class Meta: model = Map fields = ('name', 'slug', 'description')

    Read the article

  • Limit number of views per day in Django

    - by ariddell
    Is there an easy way to limit the number of times a view can be accessed by a given IP address per day/week? A simplified version of the technique used by some booksellers to limit the number of pages of a book you can preview? There's only one view that this limit need apply to--i.e. it's not a general limit--and it would be nice if I could just have a variable overlimit in the template context. The solution need not be terribly robust, but limiting by IP address seemed like a better idea than using a cookie. I've looked into the session middleware but it doesn't make any references to tracking IP addresses as far as I can tell. Has anyone encountered this problem?

    Read the article

  • input_formats in django admin has no effect

    - by pablo
    I'm trying to use input_foramts in the admin but it has no effect. What am I doing wrong? # model class Feedback(models.Model): created_at = models.DateTimeField(auto_now_add=True) # admin form class FeedbackAdminForm(forms.ModelForm): created_at = forms.DateTimeField(input_formats=('%d/%m/%Y',)) class Meta: model = Feedback # admin class FeedbackAdmin(admin.ModelAdmin): form = FeedbackAdminForm admin.site.register(Feedback, FeedbackAdmin) Thanks

    Read the article

  • How to host 50 domains/sites with common Django code base

    - by Off Rhoden
    I have 50 different websites that use the same layout and code base, but mostly non-overlapping data (regional support sites, not link farm). Is there a way to have a single installation of the code and run all 50 at the same time? When I have a bug to fix (or deploy new feature), I want to deploy ONE time + 1 restart and be done with it. Also: Code needs to know what domain the request is coming to so the appropriate data is displayed.

    Read the article

  • Django: order by count of a ForeignKey field?

    - by AP257
    This is almost certainly a duplicate question, in which case apologies, but I've been searching for around half an hour on SO and can't find the answer here. I'm probably using the wrong search terms, sorry. I have a User model and a Submission model. Each Submission has a ForeignKey field called user_submitted for the User who uploaded it. class Submission(models.Model): uploaded_by = models.ForeignKey('User') class User(models.Model): name = models.CharField(max_length=250 ) My question is pretty simple: how can I get a list of the three users with the most Submissions? I trued creating a num_submissions method on the User model: def num_submissions(self): num_submissions = Submission.objects.filter(uploaded_by=self).count() return num_submissions and then doing: top_users = User.objects.filter(problem_user=False).order_by('num_submissions')[:3] but this fails, as do all the other things I've tried. Can I actually do it using a smart database query? Or should I just do something more hacky in the views file?

    Read the article

  • Writing a custom auth system (like the default django auth system), use it to generate tables in DB

    - by dotty
    Hay all, I've been reading up on middleware and how to use it with a context object. I want to write a simple middleware class which i can use on my own applications, it will essentially be a cut down version of the django one. The problem i seem to have is that if i have INSTALLED_APPS = ('django.contrib.my_auth') in the settings file, all is well. I've also added MIDDLEWARE_CLASSES = ('django.contrib.my_auth.middleware.MyAuthMiddleware') in it and everything is fine. My question is, how would i make my middleware automatically generate tables from a models.py module, much like how the django auth does when i run manage.py syncdb? thanks

    Read the article

  • Google App Engine django model form does not pick up BlobProperty

    - by Wes
    I have the following model: class Image(db.Model): auction = db.ReferenceProperty(Auction) image = db.BlobProperty() thumb = db.BlobProperty() caption = db.StringProperty() item_to_tag = db.StringProperty() And the following form: class ImageForm(djangoforms.ModelForm): class Meta: model = Image When I call ImageForm(), only the non-Blob fields are created, like this: <tr><th><label for="id_auction">Auction:</label></th><td><select name="auction" id="id_auction"> <option value="" selected="selected">---------</option> <option value="ahRoYXJ0bWFuYXVjdGlvbmVlcmluZ3INCxIHQXVjdGlvbhgKDA">2010-06-19 11:00:00</option> </select></td></tr> <tr><th><label for="id_caption">Caption:</label></th><td><input type="text" name="caption" id="id_caption" /></td></tr> <tr><th><label for="id_item_to_tag">Item to tag:</label></th><td><input type="text" name="item_to_tag" id="id_item_to_tag" /></td></tr> I want the Blob fields to be included in the form as well (as file inputs). What am I doing wrong?

    Read the article

  • Django finding which field matched in a multiple OR query

    - by Greg Hinch
    I've got a couple models which are set up something like this: class Bar(models.Model): baz = models.CharField() class Foo(models.Model): bar1 = models.ForeignKey(Bar) bar2 = models.ForeignKey(Bar) bar3 = models.ForeignKey(Bar) And elsewhere in the code, I end up with an instance of Bar, and need to find the Foo it is attached to in some capacity. Right now I came up with doing a multiple OR query using Q, something like this: foo_inst = Foo.objects.get(Q(bar1=bar_inst) | Q(bar2=bar_inst) | Q(bar3=bar_inst)) What I need to figure out is, which of the 3 cases actually hit, at least the name of the member (bar1, bar2, or bar3). Is there a good way to do this? Is there a better way to structure the query to glean that information?

    Read the article

  • Django: get count of ForeignKey item in template?

    - by AP257
    Straightforward question - apologies if it is a duplicate, but I can't find the answer if so. I have a User model and a Submission model, like this: class Submission(models.Model): uploaded_by = models.ForeignKey('User') class User(models.Model): name = models.CharField(max_length=250 ) How can I show the number of Submissions made by each user in the template? I've tried {{ user.submission.count }}, like this: for user in users: {{ user.name }} ({{ user.submission.count }} submissions) but no luck...

    Read the article

  • django model relation definition

    - by Laurent Luce
    Hello, Let say I have 3 models: A, B and C with the following relations. A can have many B and many C. B can have many C Is the following correct: class A(models.Model): ... class B(models.Model): ... a = ForeignKey(A) class C(models.Model): ... a = ForeignKey(A) b = ForeignKey(B)

    Read the article

  • Per instance dynamic fields django model

    - by Roberto Rosario
    I have a model with a JSON field or a link to a CouchDB document. I can currently access the dynamic informaction in a way such as: genericdocument.objects.get(pk=1) == genericdocument.json_field['sample subfield'] instead I would like genericdocument.sample_subfield to maintain compatibility with all the apps the project currently shares.

    Read the article

  • Can this django query be improved?

    - by Hobhouse
    Given a model structure like this: class Book(models.Model): user = models.ForeignKey(User) class Readingdate(models.Model): book = models.ForeignKey(Book) date = models.DateField() One book may have several readingdates. How do I list books having at least one readingdate within a specific year? I can do this: from_date = datetime.date(2010,1,1) to_date = datetime.date(2010,12,31) book_ids = Readingdate.objects\ .filter(date__range=(from_date,to_date))\ .values_list('book_id', flat=True) books_read_2010 = Book.objects.filter(id__in=book_ids) Is it possible to do this with one queryset, or is this the best way?

    Read the article

  • django sort by manytomany relationship

    - by Marconi
    I have the following model: class Service(models.Model): ratings = models.ManyToManyField(User) Now if I wanna get all the service with ratings sorted in descending order I did something: services_list = Service.objects.filter(ratings__gt=0).distinct() services_list = list(services_list) services_list.sort(key=lambda service: service.ratings.all().count(), reverse=True) As you can see its a three step process and I don't feel right about this. Anybody who knows a better way to do this?

    Read the article

  • Wordpress & Django -- One domain, two servers. Possible?

    - by DomoDomo
    My question is about hosting Django and Wordpress under one domain, but two physical machines (actually, they are VMs but same diff). Let's say I have a Django webapp at example.com. I'd like to start a Wordpress blog about my webapp, so any blog page rank mojo flows back to my webapp, I'd like the blog address t be example.com/blog. My understanding is blog.example.com would not transfer said page rank mojo. Because I'm worried about Wordpress security flaws compromising my Django webapp, I want to host Django and Wordpress on two physically separate machines. Given all that, is it possible using re-write rules or a reverse proxy server to do this? I know the easy way is to make my Wordpress blog a subdomain, but I really don't want to do that. Has anyone done this in the past, is it stable? If I need a third server to be a dedicated reverse proxy, that's totally fine. Thanks!

    Read the article

  • Creating a Group of Groups in Django

    - by Greg
    I'm creating my own Group model; I'm not referring to the builtin Group model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group. The admin interface won't let me create a group without entering a parent. I get the error personnel_group.parent_id may not be NULL. My Group model looks like this: class Group(models.Model): name = models.CharField(max_length=50) parent = models.ForeignKey('self', blank=True, null=True) order = models.IntegerField() icon = models.ImageField(upload_to='groups', blank=True, null=True) description = models.TextField(blank=True, null=True) How can I accomplish this? Thanks.

    Read the article

  • Django | how to append form field to the urlconf

    - by MMRUser
    I want to pass a form's field value to the next page (template) after user submit the page, the field could be user name, consider the following setup def form_submit(request): if request.method == 'POST': form = UsersForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: newUser = form.save() return HttpResponseRedirect('/mysite/nextpage/') except Exception, ex: return HttpResponse("Ane apoi %s" % str(ex)) else: return HttpResponse('Error') "nextpage" is the template that renders after user submit the form, so I want to know how to append the form's field (user name) to the url and get that value from the view in order to pass it to the next page.. thanks.

    Read the article

  • django ifequal naturalday

    - by Scott Willman
    I'm not sure why, but this condition will never evaluate True for me. I'm feeding it datetime.today() in the urls file. Am I missing something? Template: {% load humaize %} {{ entry.date|naturalday }} {# Evals to "today" #} {% ifequal entry.date|naturalday "today" %} True {{ entry.date|date:"fA"|lower }} {{ entry.date|naturalday|title }} {% else %} False {{ entry.date|naturalday|title }} {% endifequal %}

    Read the article

  • Django | capture sub domain as a string

    - by MMRUser
    How do I capture a part of sub-domain name and get that name as a string in my views through a request. ex: user.domain.com developer.domain.com I want to capture the user part of this domain name through a request (lets say when the first time user hits the page). Thanks.

    Read the article

  • Keeping filters in Django Admin

    - by Tomo
    What I would like to achive is: I go to admin site, apply some filters to the list of objects I click and object edit, edit, edit, hit 'Save' Site takes me to the list of objects... unfiltered. I'd like to have the filter from step 1 remembered and applied. Is there an easy way to do it?

    Read the article

< Previous Page | 77 78 79 80 81 82 83 84 85 86 87 88  | Next Page >