Search Results

Search found 7702 results on 309 pages for 'django validation'.

Page 95/309 | < Previous Page | 91 92 93 94 95 96 97 98 99 100 101 102  | Next Page >

  • django url tag performance

    - by zxygentoo
    I was trying to integrate django-voting into my project following the RedditStyleVoting instruction. In my urls.py, i did something like this: url(r'^sections/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$', vote_on_object, dict( model=Section, template_object_name='section', template_name='script/section_confirm_vote.html', allow_xmlhttprequest=True ), name="section_vote", then, in my template: {% vote_by_user user on section as vote %} {% score_for_object section as score %} {% vote_by_user user on section as vote %} {% score_for_object section as score %} {{ score.score|default:0 }} It takes over 1.3s to load the page, but by hard coding it like this: {% vote_by_user user on section as vote %} {% score_for_object section as score %} {{ score.score|default:0 }} I got 50ms. Just avoid the url tag resolving stuff I got a 20+ times performance improvement. Is there something I did wrong? If not, then what's the best practice here, should we do things the right way or the fast way?

    Read the article

  • clean method for validation

    - by apoorva
    hi.. i have the following form class with corresponding clean methods... class SOFIATMUserLogin(forms.Form): Username=forms.CharField(label='Username') Password=forms.CharField(label='Password', widget=forms.PasswordInput) def clean_Username(self): user=self.cleaned_data['Username'] try: SOFIALogin.objects.get(UserName=user) except Exception: raise forms.ValidationError('Username invalid...') def clean_Password(self): upass=self.cleaned_data['Password'] In the clean_Password method i wish to check if the password entered for the valid username is correct... So i need to get the Username value... How can i access this in clean_Password method... Please assist!!!!

    Read the article

  • Django dictionary in templates: Grab key from another objects attribute

    - by Jordan Messina
    I have a dictionary called number_devices I'm passing to a template, the dictionary keys are the ids of a list of objects I'm also passing to the template (called implementations). I'm iterating over the list of objects and then trying to use the object.id to get a value out of the dict like so: {% for implementation in implementations %} {{ number_devices.implementation.id }} {% endfor %} Unfortunately number_devices.implementation is evaluated first, then the result.id is evaluated obviously returning and displaying nothing. I can't use parentheses like: {{ number_devices.(implementation.id) }} because I get a parse error. How do I get around this annoyance in Django templates? Thanks for any help!

    Read the article

  • Django: Localization Issue

    - by Eric
    In my application, I have a dictionary of phrases that are used throughout of the application. This same dictionary is used to create PDFs and Excel Spreadsheets. The dictionary looks like so: GLOBAL_MRD_VOCAB = { 'fiscal_year': _('Fiscal Year'), 'region': _('Region / Focal Area'), 'prepared_by': _('Preparer Name'), 'review_cycle':_('Review Period'), ... snip ... } In the code to produce the PDF, I have: fy = dashboard_v.fiscal_year fy_label = GLOBAL_MRD_VOCAB['fiscal_year'] rg = dashboard_v.dashboard.region rg_label = GLOBAL_MRD_VOCAB['region'] rc = dashboard_v.review_cycle rc_label = GLOBAL_MRD_VOCAB['review_cycle'] pb = dashboard_v.prepared_by pb_label = GLOBAL_MRD_VOCAB['prepared_by'] Now, when the PDF is produced, in the PDF, I don't see these labels but rather, I see: <django.utils.functional.__proxy__ object at 0x10106fdd0> Can somebody help me with this? How do I get the properly translated labels? Thanks Eric

    Read the article

  • Django. default=datetime.now() problem

    - by Shamanu4
    Hello. I've such db model: from datetime import datetime class TermPayment(models.Model): dev_session = models.ForeignKey(DeviceSession, related_name='payments') user_session = models.ForeignKey(UserSession, related_name='payment') date = models.DateTimeField(default=datetime.now(),blank=True) sum = models.FloatField(default=0) cnt = models.IntegerField(default=0) class Meta: db_table = 'term_payments' ordering = ['-date'] and here new instance is added: # ... tp = TermPayment() tp.dev_session = self.conn.session # device session hash tp.user_session = self.session # user session hash tp.sum = sum tp.cnt = cnt tp.save() But i've a problem: all records in database have the same value in date field - the date of the first payment. After server restart - one record have new date and others have the same as first after restart. It's look like some data cache is using but I can't found where. database: mysql 5.1.25 django v1.1.1

    Read the article

  • Django admin page dropdowns

    - by zen
    I am building a high school team application using Django. Here is my working models file: class Directory(models.Model): school = models.CharField(max_length=60) website = models.URLField() district = models.SmallIntegerField() conference = models.ForeignKey(Conference) class Conference(models.Model): conference_name = models.CharField(max_length=50) url = models.URLField() class Meta: ordering = ['conference_name'] When I open my admin pages and go to edit a school's conference the drop down looks like this: <select> <option value="1">Conference Object</option> <option value="2">Conference Object</option> <select> How do I replace "Conference Object" with the conference_name?

    Read the article

  • Django complex queries

    - by Josh K
    I need to craft a filter for an object that checks date ranges. Right now I'm performing a very inefficient loop which checks all the objects. I would like to simplify this to a database call. The logic is you have a start and an end date objects. I need to check if the start OR the end is within the range of an appointment. if (start >= appointment.start && start < appointment.end) || (end > appointment.start && end <= appointment.end) I could do this in SQL, but I'm not as familiar with the Django model structure for more complex queries.

    Read the article

  • Problems trying to format currency with Python (Django)

    - by h3
    I have the following code in Django: import locale locale.setlocale( locale.LC_ALL, '' ) def format_currency(i): return locale.currency(float(i), grouping=True) It work on some computers in dev mode, but as soon as I try to deploy it on production I get this error: Exception Type: TemplateSyntaxError Exception Value: Caught ValueError while rendering: Currency formatting is not possible using the 'C' locale. Exception Location: /usr/lib/python2.6/locale.py in currency, line 240 The weird thing is that I can do this on the production server and it will work without any errors: python manage.py shell >>> import locale >>> locale.setlocale( locale.LC_ALL, '' ) 'en_CA.UTF-8' >>> locale.currency(1, grouping=True) '$1.00' I .. don't get it.i

    Read the article

  • Django - Empty session data in ajax requests

    - by ninja123
    Hi guys, I have an ajax view where I want to set a session variable like such: def upload(request, *args, **kwargs): request.session['test'] = 'test' request.session.modified = True print request.session.items() I have another normal view something like this: def advertise(request): print request.session.items() I get these two strings printed to shell: [('test', 'test')] [('_auth_user_backend', 'django.contrib.auth.backends.ModelBackend'), ('_auth_user_id', 26L)] Why is the session data that I set in the ajax view not passing to my regular views? If I set session data in regular view, everything works as fine, but it seems that ajax requests contain empty session data? Anybody dealt with something like this before? Any suggestions are greatly appreciated. Thanks.

    Read the article

  • Django colon syntax in template tags: only in newer versions?

    - by Alan
    I just deployed an application to a new server, and although I'm using virtualenv, I had to install a new environment on the production server, which has a different architecture. Anyway, I received no TemplateSytaxErrors in development, but on the production server, I get: Exception Type: TemplateSyntaxError Exception Value: Caught SyntaxError while rendering: invalid syntax (views.py, line 25) The offending line is: {% url admin:password_change as password_change_url %} Upon removing that line, the TemplateSyntaxError hops to the next line that has a colon in it (and lets other template tags work fine). So my question is this: is there some discrepancy in versions of Python/Django that would allow or disallow the namespacing syntax? The template tags are in django-grappelli (http://code.google.com/p/django-grappelli/), so I'd rather not go through their code and rewrite all the template tags. Development server: 32-bit Debian Python 2.5.5 Django 1.2.1 Production server: 64-bit CentOS Python 2.4.3 Django 1.2.1 Any ideas?

    Read the article

  • Firefox - Stashing Requests for Deliberate Resubmission to Django App

    - by Koobz
    I've got an object creation form that's somewhat complicated, it contains a few dynamic formsets etc. I'm trying to ensure that these dynamic formsets are intact if the form runs into an error and returns you to the given page. In cases like this, the refresh button actually works well in re-submitting the request, but I can't rely on it. I'm doing some ad-hoc testing in the browser that I'd like to make a bit more repeatable, and eventually move to a unit test using Django's mock client. Is there an extension, or some convenient method to stash requests for later re-submission. The goal: I resubmit the request, tweak the code, eyeball the results, rinse and repeat. Three days later I can come back to it an try it again to make sure it's still working. The closest thing I can think of in this case is simply recording my activity with Selenium ide and replaying it.

    Read the article

  • Django i18n: makemessages only on site level possible?

    - by AndiDog
    I have several strings in my site that don't belong to any app, for example {% block title %}{% trans "Login" %}{% endblock %} or a modified authentication form used to set the locale cookie class AuthenticationFormWithLocaleOption(AuthenticationForm): locale = forms.ChoiceField(choices = settings.LANGUAGES, required = False, initial = preselectedLocale, label = _("Locale/language")) Now when I execute django-admin.py makemessages --all -e .html,.template in the site directory, it extracts the strings from all Python, .html and .template files, including those in my apps. That is because I develop my apps inside that directory: Directory structure: sitename myapp1 myapp2 Is there any way to extract all strings that are not in my apps? The only solution I found is to move the app directories outside the site directory structure, but I'm using bzr-externals (similar to git submodules or svn externals) so that doesn't make sense in my case. Moving stuff that needs translation into a new app is also possible but I don't know if that is the only reasonable solution.

    Read the article

  • Django admin return to page after save

    - by Thordin9
    Hi all, I have 3 pages of items listed in my django application admin. After i edit one of them (lets say it is in page 2) and save my changes, i return to page 1 of my listing. How can i make it so i return to the page the item is in? I looked into some similar questions here at stackoverflow and i believe that i need to use javascript to send a httpresponse with the location header. But how i can determine the page the item is in? any help is appreciated

    Read the article

  • Can you iterate over chunks() with request.POST in Django?

    - by Sebastian
    I'm trying to optimize a site I'm building with Django/Flash and am having a problem using Django's iterate over chunks() feature. I'm sending an image from Flash to Django using request.POST data rather than through a form (using request.FILES). The problem I foresee is that if there is large user volume, I could potentially kill memory. But it seems that Django only allows iterating over chunks with request.FILES. Is there a way to: 1) wrap my request.POST data into a request.FILES (thus spoofing Django) or 2) use chunks() with request.POST data

    Read the article

  • Does django take SCRIPT_NAME into account when using the default LOGIN_URL

    - by DanJ
    Hi, I'm using Django 1.0.2 and trying to figure out how to get the @login_required working correctly. When I use the built-in server it redirects to the default login_url, or my LOGIN_URL as defined in settings.py as expected. What is not clear to me is how to deploy to the server where my site is not at the root. In my templates I use the url template tag, and in the views I can access request.META['SCRIPT_NAME'], but for some reason it doesn't seem to apply to the LOGIN_URL used. What am I missing? Thanks.

    Read the article

  • How to stream an HttpResponse with Django

    - by muudscope
    I'm trying to get the 'hello world' of streaming responses working for Django (1.2). I figured out how to use a generator and the yield function. But the response still not streaming. I suspect there's a middleware that's mucking with it -- maybe ETAG calculator? But I'm not sure how to disable it. Can somebody please help? Here's the "hello world" of streaming that I have so far: def stream_response(request): resp = HttpResponse( stream_response_generator()) return resp def stream_response_generator(): for x in range(1,11): yield "%s\n" % x # Returns a chunk of the response to the browser time.sleep(1)

    Read the article

  • django: Selecting questions that was not asked

    - by Oleg Tarasenko
    Hi, I am creating small django application which holds some few questions (and answers for them) What I want to do is to show user random question, but only from those which was not solved by him yet. I wonder how to do this. For now, I defined user profile model this way: class UserProfile(models.Model): rank = models.IntegerField(default = 1) solvedQ = models.ManyToManyField(Question) user = models.ForeignKey(User, unique=True) So solved problems are added this way: if user.is_authenticated(): profile = user.get_profile() profile.rank += 1 profile.solvedQ.add(Question.objects.get(id=id)) Now if the view must show random question, but not from already solved list... Is there a good way to intersect Questions and solvedQuestions.... so question is chosen from the unsolved list?

    Read the article

  • Django ORM dealing with MySQL BIT(1) field

    - by Carles Barrobés
    In a Django application, I'm trying to access an existing MySQL database created with Hibernate (a Java ORM). I reverse engineered the model using: $ manage.py inspectdb > models.py This created a nice models file from the Database and many things were quite fine. But I can't find how to properly access boolean fields, which were mapped by Hibernate as columns of type BIT(1). The inspectdb script by default creates these fields in the model as TextField and adds a comment saying that it couldn't reliably obtain the field type. I changed these to BooleanField but it doesn't work (the model objects always fetch a value of true for these fields). Using IntegerField won't work as well (e.g. in the admin these fields show strange non-ascii characters). Any hints of doing this without changing the database? (I need the existing Hibernate mappings and Java application to still work with the database).

    Read the article

  • django integrate htmls into templates

    - by dana
    hi guys, i have a django 'templating' question if i have in views.py: def cv(request): if request.user.is_authenticated(): cv = OpenCv.objects.filter(created_by=request.user) return render_to_response('cv/cv.html', { 'object_list': cv, }, context_instance=RequestContext(request)) and in cv.html something like: {% for object in object_list %} First Name {{ object.first_name }} Last Name {{ object.last_name }} Url {{object.url}} Picture {{object.picture}} Bio {{object.bio}} Date of birth {{object.date_birth}} {% endfor %} but i want this content to appear on the profile.html page too, how can i do it? a smple {% include cv.html %} in the profile.html doesn't work. Also, is there another way to 'parse the object list' than explicitly write all the objects, like above? thanks in advance!

    Read the article

  • Creating a Better Tabbed Interface in Django

    - by ygd
    I've been trying to create a tabbed interface using Django. The current effort (which works fine) is having each template have the header hard-coded in, with the selected tab given the "selected" CSS attribute. Of course, this is a massive violation of DRY and I'm looking to remedy it. My current idea is adding a jQuery script to the page that looks at all the tabs and sets one to "selected" if it's text matches the beginning of the title for the page. Is there a better way to do this without using JavaScript and just pure CSS?

    Read the article

  • Django - raw_id_fields title not refreshing.

    - by James Howell
    Hi, I am currently having an issue when using the raw_id_field within admin.py in my Django project. My site's admin area has a number of image upload fields for various different model pages which are all ForeignKey fields to an Image model where all images for the site are stored. As the site will eventually be dealing with a large quantity of images (100s, maybe 1000s) the default select box would be unusable. I created various admin.ModelAdmin classes e.g class InfoSlideAdmin(admin.ModelAdmin): raw_id_fields=('image',) These change the image selector within my Edit pages from a Select Box to a Raw ID Field. However when I select a different image using this control although the ID of the new image is shown the title from the previous image still displays. Any ideas?

    Read the article

  • DJANGO complex modelling

    - by SledgehammerPL
    Hello. I have such model now: receipt contains components. component contain product. The difference between component and product is, that component has quantity and measure unit: eg. component is 100g sugar - sugar is a product. So I need to make lots of components to satisfy different recipes - 100g sugar is not equal 200g sugar I wonder if I can remodel it to kick off components - in pure sql it's rather easy, but I'm trying to USE django - not making workarounds. class Receipt(models.Model): name = models.CharField(max_length=128) (...) components = models.ManyToManyField(Component) class Component(models.Model): quantity = models.FloatField(max_length=9) unit = models.ForeignKey(Unit) product = models.ForeignKey(Product) class Product(models.Model): name = models.CharField(max_length = 128) TIA

    Read the article

  • Django template tag basic question

    - by ninja123
    It looks like this template tag works like a charm for most people: http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/ For some reason I get this error: Caught an exception while rendering: 'is_paginated' I use this template tag in my template like so: {% load digg_paginator %} {% digg_paginator %} Where digg_paginator.py is in my app/templatetags folder and the included template context digg_paginator.html is in my app/templates folder. The queryset that needs pagination is called 'destinations'. If i just specify {% digg_paginator %}, how does it know what variable to paginate?? I feel I am missing something important here or just plain stupid :P Someone please help, or explain to me how this should be done. Thanks

    Read the article

  • Django and a referrer system question

    - by Hellnar
    Hello, I am trying develop a basic referrer system to my Django website, system will be generating a unique url for each users to share with their friends. Once these friends enter this website, system somehow keep the data that "this user is browsing by the reference of X user" and once this invited person decided to register for an account, system will save this information (maybe as an extra Foreign Key of the inviting user in the UserProfile model) Now how can I keep track of the inviting user from the moment entering using the referred link to the point where he/she registers to the site. Would session framework work on this? If not how could this be done ?

    Read the article

  • Using Django view variables inside templates

    - by William
    Hi, this is a rather basic question (I'm new to Django) but I'm having trouble using a variable set in my view inside my template. If I initialize a string or list inside my view (i.e. h = "hello") and then attempt to call it inside a template: {{ h }} there is neither output nor errors. Similarly, if I try to use a variable inside my template that doesn't exist: {{ asdfdsadf }} there is again no error reported. Is this normal? And how can I use my variables within my templates. Thanks!

    Read the article

< Previous Page | 91 92 93 94 95 96 97 98 99 100 101 102  | Next Page >