django

Distinct elements in django model

I'm a Django newbie and I wonder if there is a more efficient way (at a database level) of doing the following. I have the model: class Foo(models.Model): item=models.IntegerField() another_item=models.IntegerField() And want to get an iterable of all the distinct values of "item". This is what I have so far: distinct=set([...

How to access url hash/fragment from a Django Request object

As in the title: how can I access the url hash/fragment (the part following the dash #) from a Django view and so, I suppose, from a Django Request object? I've not found enough information on the documentation here available: http://docs.djangoproject.com/en/dev/ref/request-response/ P.S. Suppose that the fragment part is sent to the ...

what is 'comments' mean in this code.

{% load comments %} where defined 'comments' ,a viewer? or a template?? thanks ...

Looking for a django app for running my blog

Hi, I am looking for a django blog application to run my blog. I have found following options available: django-basic-blog Byteflow Can you please share your recommendation. My basic requirements are: - Easy to customize - Having basic blog capabilities ...

How do I reply to an email using the Python imaplib and include the original message?

I'm currently using imaplib to fetch email messages from a server and process the contents and attachments. I'd like to reply to the messages with a status/error message and links to the resulting generated content on my site if they can be processed. This should include the original message but should drop any attachments (which will ...

Custom Django Form

I'm trying to make a custom backend for my system and I've hit a bit of a snag....I want to give users the ability to add new makes/models/series that are not already in the system via a form. I'm wondering how I'll go about this...my models look as below: class Manufacturer(models.Model): MANUFACTURER_POPULARITY_CHOICES = ( ('1',...

Django templates condition check

All, Can t we do the following in templates {% if subject.id == selected_id %} and also cannot we assign variable like {{selected="selected"}} Thank........ ...

Expando Model in Django

Is it possible to implement 'expando' model in Django, much like Google App Engine has? I found a django app named django-expando on github but it's still in early phase. ...

django admin hierarchical inline model edit.

Consider a wiki application. There is a model Page, that has many Revisions and each revision has many blocks. What is the simplest way to create an admin in which, you select a page and all the blocks of the latest revision appear; bonus points for letting change of revision by a dropdown (which is by default, sorted in reverse order a...

Django template-printing variables

All, In Template condition check,whats wrong with the following code, selected_id and selected_sub are equal to 5 but still ifequal loop is not working.. <tr><td><p>Subjects:</td> <td> <select id="subjects" name="subjects" multiple="multiple"> {% for subject in subjects %} <option value="{{subject.id}}" {% for selected_id in selected_...

Hide filter items that produce zero results in django-filter

I have an issue with the django-filter application: how to hide the items that will produce zero results. I think that there is a simple method to do this, but idk how. I'm using the LinkWidget on a ModelChoiceFilter, like this: provider = django_filters.ModelChoiceFilter(queryset=Provider.objects.all(), widget=django_filters.widg...

django routes help

Hay guys, im making a simple car sale website. I have a nice little urlpattern which works well as expected /car/1/ goes to a car with that id, simple? However, for SEO reasons i want to add extra data to the URL, but ignore it. /car/1/ford/focus as an example, how would i go about modifying my patters to take the extra parts into...

include sessions inside an inclusion

hay Guys, i cannot seem to access request.sessions inside my inclusion template. Any ideas how i can get this data? The sessions are my own, custom ones. my inclusion looks like @register.inclusion_tag('base/side_bar.html', takes_context=True) def show_side_bar(context): models = Model.objects.all() makes = Make.objects.all...

Populate ChoiceField from database

I'd like to have several fields in my form being rendered as ChoiceFields which get their content from the database. I was thinking something like: class SeriesForm(ModelForm): series = forms.ChoiceField(choices=Series.objects.all()) class Meta: model = Series exclude = ('model', 'date_added',) But the field series is no...

How to receive uploaded file from the inlined form in django?

I'm trying to create a "cool" image uploading interface in django admin panel. The problem is that I'm using inline interface for uploading image instances, but I'm using jQuery Ajax form to upload images, so there were another form I need to create for uploading. And now django view function can't receive request.FILES from this form, b...

Django Custom Admin Ordering

Hi there I have a list of images in my admin area. I would like to add a upp/down button to every field. Clicking on the up field will move the image up in the order of images. So lets say its number 3 on the list and i click on it, it should now move to number 2. and also the same for moving down in the order of the list bly clicking o...

Easy Way to Escape Django Template Variables

For a new project we're writing documentation about the Django template system. We use Django for the documentation project itself too, so Django picks up all our example variables in the sample code and tries to render them. The only way we found to get around this is to use {% templatetag %}, but that makes our code really unreadable. ...

django templates, find string replace with other string

Hay, I'm writing some templates but i want to convert " " into "_" within a string. I want to convert {{ user.name }} Which outputs "My Name" to "My_Name" how do i do this? Thanks ...

How can I catch server json response while uploading image using Ajax?

I have a form which is loaded via jQuery from the external template file: $('#imguploadform').html('&nbsp;').load('{% url upload_form %}'); In template it looks like this: <img src="{{ MEDIA_URL }}img/misc/upload.png" alt="Illustration" title="myimage" /> <form id="uploadForm" enctype="multipart/form-data" method="post" action="uploa...

Django: How do I get an array from a QueryDict in a template?

hi, I've got the following QueryDict object in my request.session. <QueryDict: {u'category': [u'44', u'46'], u'cityID': [u'null'], u'countryCode': [u''], u'mapCenterLng': [u'2.291300800000009'], u'mapZoom': [u'12'], u'mapCenterLat': [u'47.10983460000001'], u'price_range': [u''], u'textbox': [u'']}> In a template try to get the catego...