django-views

Django update table

obj = Info(name= sub,question=response_dict["question"]) obj.save() After saving the data how to update another field of the same table obj.err_flag=1 obj.update()//Will this work ...

Django - Minimum time between posts

My models: class Entry(models.Model): title = models.CharField(_('Title'), max_length=200) content = models.TextField(_('Content')) created_at = models.DateTimeField(auto_now_add=True) My models is used for multi-user. So, how to set a value to handle minimum time between posts? Please give me some codes. Thanks so much! ...

Create directory while upload using django

After uploading a file from the UI, how to create the a new directory with the current timestamp in /opt/files/ and copy the uploaded zip file to this directory, and unzip the zip file in the new directory and maintain the new directory name in a variable def upload_info(request): if request.method == 'POST': fi...

filter on a many_to_many field

Hi, new to django, this might be a simple/obvious question, so I apologise in advance. I have the following model class Team(models.Model): name = models.CharField(max_length=100) members = models.ManyToManyField(User, related_name="members", blank=True, null=True) And the following view (controller) def my_teams(request): ...

How to cater for 'AnonymousUser' when filtering based on user

I have the following model class Team(models.Model): name = models.CharField(max_length=100) members = models.ManyToManyField(User, related_name="members", blank=True, null=True) And the following view (controller) def my_teams(request): my_list = Team.objects.filter(members=request.user).order_by('name') return rende...

Shifting thinking from CakePHP to Django - a monolithic views file?

I'm trying to get started with Django, and have previously worked with CakePHP, and so my MVC background comes out of that. I'm aware of Django's slightly different MTV architecture, and am fine with the monolithic model files - multiple classes in one file I can handle just fine. But I'm confused about how to do the views (which are r...

How to return a objects details only when a condition is met (request.user is listed in a linked M2M field)

I have the following model class Team(models.Model): name = models.CharField(max_length=100) members = models.ManyToManyField(User, related_name="members", blank=True, null=True) And the following view def team_details(request, team_id): # Look up the Team (and raise a 404 if it is not found) team = get_object_or_404...

Decode values from django request

How to decode the values from request from django FW. GET:<QueryDict: {}>, POST:<QueryDict: {u'objarrid': [u'1035', u'1036', u'1037', u'1038', u'1039', u'1040', u'1041', u'1042']}>, def get_data(request): try: if request.method == 'GET': r_c = request.GET elif request.method == 'POST': r_c = request.POST except:...

Django:How can I ensure that a view can only be directed from another view

I have two views def view1(request): do something return HttpResponseRedirect(reverse(view2), args1) Now I need view2 to only work if it's referred by view1. How do I do that? I did read it somewhere, not able to recollect @somefilter def view2(request): do something #view2 will only be referred from view1, else Http...

Django jQuery views user question

I seem to be stuck and am not sure which is the best direction to take. I have a few apps in my project and would like to combine three views into one template. I have a userprofile in which I would like to display his info, latest news feeds and also his photos Through this I am making use of jQuery tabs I have defined my three tabs...

Passing an array in django urls

Can we pass an array to a django url <script> function save() { window.location = "/display/xlsdisplay/" + objarr ; } var objarr = new Array(); </script> Urls.py (r'^xlsdisplay/(?P<qid>\d+)$', 'xlsdisplay'), There is an error saying http://192.168.1.11/display/xlsdispla...

querying a array in django

idarr = [1,2,3,4,5] for i in range(len(idarr)): upload.objects.filter(idarr[i]) Cant we pass the idarr at one shot to the query ...

Where can I save a variable to be used between calls to a Django view?

I am looking to return a random number between 0 and 4 in a Django view, which is repeatedly called. The number is limited in that it can't be the same as the number that was called previously. It would be fine if the number loops rather than being random, it just can't be the same as what was returned before. I tried using a variable o...

Django app to retrieve data from other apps models?

I have an app name sync which has a form created from a model that saves itself. I want to create another app called activity that retrieves the data from the sync models and other future apps. How can I do that in the activity views app? This is my sync models.py from django.db import models from django.contrib.auth.models import User...

Django view to retrieve data from model returns object name only

I have a model with data in it defined like this: class SyncJob(models.Model): date = models.DateTimeField() user = models.ForeignKey(User, unique=False) source = models.CharField(max_length=3, choices=FS_CHOICES) destination = models.CharField(max_length=3, choices=FS_CHOICES) options = models.CharField(max_length=10, choices...

How to add app to all pages in django?

I have an app called lastapp that I would like it to be viewable on all pages. It renders base.html so it's available on all apps. So far I've tried adding it to the urls.py like this: urlpatterns = patterns('', (r'^first/$', firstapp, lastapp), (r'^last/$', lastapp), ) But when I go to /first/ it gives me the error: Error,...

How to use Django to manage free spaces in a group of users?

I have the following (stripped down) code: # games/models.py side_choices = [('A', 'Attack'), ('D', 'Defense')] position_choices = [(0, 'Commander'), (1, 'Knight'), (2, 'Mage'), (3, 'Healer')] class Game(models.Model): users = models.ManyToManyField(User, through='GameParticipation)) // User is Django's user class GameParticipatio...

Getting related

Hi guys, i having problem with this: model.py (1) class Profession(models.Model): user= models.ForeignKey(User,unique=True) principal_area = models.ForeignKey(Area,verbose_name='Area principal',related_name='area_principal') others_areas = models.ManyToManyField(Area) model.py (2) class Area(models.Model): area = mod...

Get Value Of Selected Option ModelChoiceField

Without using Ajax is there a way to get the value of a selected item. So for example, if I have the below drop down list: <select name="controllers" id="id_controllers"> <option value="" selected="selected">---------</option> <option value="1">http://przemeklach.com/api/firstOrder/przemeksController&lt;/option&gt; <option value="5">ht...

Refresh template in Django

Hi. I have a view like this: def form1(request): if request.method == 'POST': form = SyncJobForm(request.POST) if form.is_valid(): # do something in_progress = True return render_to_response('form1.html', {'in_progress': in_progress}) I would like to know how to set it to refresh the templat...