django

changing options according to the user choice

Hi, In my class I have about 12 fields. One field is status, another is reason. When I go to the edit page in the django admin, I only want to show the second field (reason field) if the status=='rejected'. The problem is very simple: just showing the fields according to the user input. ...

django Authentication using auth.views

User should be redirected to the Login page after registration and after logout. In both cases there must be a message displayed indicating relevant messages. Using the django.contrib.auth.views.login how do I send these {{ info }} messages. A possible option would be to copy the auth.views to new registration module and include all es...

django - reorder queryset after slicing it

I fetch the latest 5 rows from a Foo model which is ordered by a datetime field. qs = Foo.objects.all()[:5] In the following step, I want to reorder the queryset by some other criteria (actually, by the same datetime field in the opposite direction). But reordering after a slice is not permitted. reverse() undoes the first ordering, g...

How to store the name of user logged in?

I want to store the name of the user who is currently logged into Django in a custom form. In the admin we can do so by writing modified_by=request.user.username, but how do I do this in my own form? ...

Django can't http request its own pages?

At one point, my Django app needs to load one of its own pages to render another page. I'm trying to use urllib2 (working with Python 2.6) to load the page, but it appears that the newer request is blocked until the former completes. Is this a problem with Django using only one thread in debug mode? (I'm running it simply with the defau...

How do I update an object's members using a dict?

I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL. So some internal application sends off a request to /import/?a=1&b=2&c=3, for example. In the view, I want to create a new object, foo = Foo() and have the members of foo set to the data in the request.GE...

Problem of creating new generic related object inside admin generic inline forms

I have strange problem with admin generic inline forms. I have two models, main Project and Video with ManyToMany relation trough VideoLink, becouse I need to be able linking different number of Video to Project and many project to Video: class VideoLink(models.Model): content_type = models.ForeignKey(ContentType) object_id = mo...

Validating a slug in Django

Hi I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to £$(*£$(£@$&£($ in the title field, which is converted into a slug using Django slugify. Because none of these characters can be converted, Django returns an error. My question ...

Django 1.0, using default password reset

I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error: Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments ... in my urlconf I ...

Missing 'Median' Aggregate Function in Django?

The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (link text). Is there a reason Median is missing from the list? Implementing one seems like it would be easy. Am I missing something? How much are the aggregate functions doing behind the scenes? ...

Why can't I nest a block tag inside an if tag?

I have a master template file called base.html, in it I have the following code: {% ifequal environment "dev" %} {% block stylesheets %}{% endblock %} {% endifequal %} I inherit this in other templates and do the following: {% block stylesheets %} <link ... > {% endblock %} The problem is, the stylesheet I link never gets a...

Does Django development follow the Bazaar Model of development?

Some would argue that Bazaar Model of development can lead to a tangled mess of cowboy code. I'm wondering, which model does Django follow? At first glance it seems to be a highly organized bazaar model, with vetting and triage stages and such. However, the source is available at all times, but not every patch or suggestion gets rando...

Django model inheritance w/ custom inclusion_tags

I'm gonna try and simplify this as much as possible. Lets say i have the following: models.py class Person(models.Model): name = models.CharField(max_length=255) def getRealPerson(self): # is there a better way to do this? ret = None try: ret = self.worker except: try: ...

Benefit of installing Django from .deb versus .tar.gz?

I'm starting Django development, and I can either install it from the .deb using $ apt-get install python-django on my Ubuntu machine, or I can download the .tar.gz from djangoproject.com, and start with that. What are the benefits and drawbacks of each approach? ...

Publish feeds using Django

I'm publishing a feed from a Django application. I subclassed django.contrib.syndication.feeds.Feed, everything works fine, except the date that doesn't get published on the feed. Here's the method I've created on my Feed class def item_pubdate(self, item): return item.date this method never gets called.... ...

Difference between admin.site.root and admin.site.urls

In the The Django Book in chapter 6 about the Admin Site, they tell me to add the follwing URLpattern to urls.py: urlpatterns = patterns('', # ... (r'^admin/', include(admin.site.urls)), # ... ) But to make it work on my system, I had to uncomment the following line: (r'^admin/(.*)', admin.site.root), Can somebody enlig...

Form widget for text inputs with external link wanted!

I keep field imdb_id for models Movie in my db: class Movie(models.Model): imdb_id = models.IntegerField('imdb ID', blank=True, null=True, unique=True) def _get_imdb_url(self): return self.imdb_id and 'http://www.imdb.com/title/tt%s/' % str(self.imdb_id).zfill(7) or '' def _set_imdb_url(self, imdb_url): sel...

How to I reload global vars on every page refresh in DJango

Here is my problem. DJango continues to store all the global objects after the first run of a script. For instance, an object you instantiate in views.py globally will be there until you restart the app server. This is fine unless your object is tied to some outside resource that may time out. Now the way I was thinking to correct wa...

How can I get an accurate absolute url from get_absolute_url with an included urls.py in Django?

I've building a app right now that I'm trying to keep properly decoupled from the other apps in my Django project (feel free to lecture me on keeping Django apps decoupled, I'd be happy to learn more any/all the time). My problem is this: The get_ absolute_url() method I've written is returning a relative path based on my view. I think ...

method for creating a unique validation key/number

I'm using django for a web-magazine with subscriber-content. when a user purchases a subscription, the site will create a validation key, and send it to the user email address. The validation key would be added to a list of "valid keys" until it is used. What is the best method for creating a simple yet unique key? Can someone suggest...