django-views

Reorganizing many to many relationships in Django

I have a many to many relationship in my models and i'm trying to reorganize it on one of my pages. My site has videos. On each video's page i'm trying to list the actors that are in that video with links to each time they are in the video(the links will skip to that part of the video) Here's an illustration Flash Video embedded he...

Django get old url

In django views,From the request how would we know from which page this view was called def password_change(request): if request.method == 'POST': u=request.user u.set_password(request.POST.get('new_password')) u.save() post_change_redirect= //Need old link here return HttpResponseRedirect(post_change_...

Django multilanguage support

Using django if a text is stored in French or Hindi.How will this be stored and retrieved in a text box field Models.py class Details(models.Model): title = models.CharField(max_length = 255) html page: <form action="/pjt/details"> <input type="text" name="nee_n"id="neen_n" /> </form> How to store this in the ...

Displaying scraped results in Django template

I'm test building a scraping site with django. For some reason the following code is only providing one picture image where i'd like it to print every image, every link, and every price, any help? (also, if you guys know how to place this data into a database model so I don't have to always scrape the site, i'm all ears but that may be a...

How to disable Middleware and Request Context in some views.

I am creating a chat like facebook chat... so in views.py of my Chat Application, I need to retrieve only the last messages every 3-4 seconds with ajax poll ( the latency is not a problem for me ). If I can disable some Middlewares and some Request Context in this view, the response will be faster... no ? My question is: Is there a w...

How to save a custom cookie

Is there a way to save a cookie that is available on other site ? For instance I have my django project on http://www.example.com and I want that django saves a cookies for a site written in PHP on http://site.Idontknow.com . Is this possible ? ...

Best way to write an image to a Django HttpResponse()

I need to serve images securely to validated users only (i.e. they can't be served as static files). I currently have the following Python view in my Django project, but it seems inefficient. Any ideas for a better way? def secureImage(request,imagePath): response = HttpResponse(mimetype="image/png") img = Image.open(imagePath...

How to make custom join query with Django ?

I have these 2 models: genre = ( ('D', 'Dramatic'), ('T', 'Thriller'), ('L', 'Love'), ) class Book(models.Model): title = models.CharField(max_length=100) genre = models.CharField(max_length=1, choices=genre) class Author(models.Model): user = models.ForeignKey(User, unique=True) born = models.DateTimeF...

Django templates tag error

def _table_(request,id,has_permissions): dict = {} dict.update(get_newdata(request,rid)) return render_to_response('home/_display.html',context_instance=RequestContext(request,{'dict': dict, 'rid' : rid, 'has_permissions' : str(has_permissions)})) In templates the code is as, {% if has_permissions == "1" %} <input type="b...

Django models avoid duplicates

In models, class Getdata(models.Model): title = models.CharField(max_length=255) state = models.CharField(max_length=2, choices=STATE, default="0") name = models.ForeignKey(School) created_by = models.ForeignKey(profile) def __unicode__(self): return self.id() In templates <form> <input type="submit" s...

chat app. for django

Is there any facebook like chat application to integrate to django.If so please give an example and the source link Thanks.. ...

set user session in django

<?php session_start(); $_SESSION['username'] = "johndoe" // Must be already set ?> How to write equivalent code for the above in django ...

Django view decorator

Hello All, I'm trying to write a decorator in my views file but when the decorated function is returned django complains that the view does not have an HttpResponseObject. How do I return a decorated view without running the rest of the view code. Or should I just be using a function. enter code here def special_check(f): def wrap...

django tar generation on request

Greetings, By using Django, I want to generate a tar.gz which contains the files below, and render a tar.gz file: Content from an Ubuntu server: /home/user/myfolder /home/user/image.jpg an xml file from www.mysite.com/foo.xml (which is a dynamicly generated xml file. Rendered tar.gz file myfolder/ content/ ..... ...

django delete object

Hello, in a mini blog app, i want to create a delete function, so that the owner of the blog can delete his entries (and only his entries). I guess that the only methos for doing do, is using a form. Though my the deletion code seems clear and correct, it doesn;t work. My code: def delete_new(request,id): u = New.objects.get(pk=id).d...

URLs and side effects (Django)

I'm wondering if it's considered okay (particularly, in Django) to have a URL that's only intended for actions with side effects, that's only intended to be accessed by POST, and that is basically invisible to the user. Let's say, for the sake of making this concrete, I have a little messaging system on my site, and from their inbox, a u...

Returning values from methods in Django

Hi! So, time for a newbie question but so utterly important since the documentation seems to have missed this very very basic example. All I'm trying to do is to return a value from a model to a view in Django. Here is some code. The model class Page(models.Model): def index(self): ex = 'foo string' return ex The vie...

Django: Hierarchical URLs

How do you deal with hierarchical URLs in Django? Any best practices for that? Eg. If I would have an URL like /blog/category1/category2/myblogentry (using eg. django-mptt), would you do some checking before in urls.py or give the whole path to a view, let it check every part if it is a valid category etc? Doesn't sound so tough, but ju...

Popup waiting for user action in Django

In my project I have to add functionality for deleting friends from users list. When clicking on 'Delete friend' link, the following view is loaded (with the friends.id sent) : def delete_friend(request, id): friend = get_object_or_404(Friend, id=id) friend.delete() return HttpResponseRedirect(reverse('user_profile',)) ...

how to serve generated files via django

Hello I am generating tar.gz files with Django and save it to somewhere like /home/foo/foo.tar.gz but I don't know what is a good way to serve these generated files under django view. I am using return HttpResponseRedirect("/home/foo/foo.tar.gz") but it is actually not a good way to serve tar.gz files because the generated tar.gz file p...