Search Results

Search found 26207 results on 1049 pages for 'django users'.

Page 7/1049 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • How to make custom join query with Django ?

    - by xRobot
    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.DateTimeField('born') book = models.ForeignKey(Book) I need to retrieve first_name and last_name of all authors of dramatic's books. How can I do this in django ?

    Read the article

  • Django: name of many to many items in the admin interface

    - by Adam
    I have a many to many field, which I'm displaying in the django admin panel. When I add multiple items, they all come up as "ASGGroup object" in the display selector. Instead, I want them to come up as whatever the ASGGroup.name field is set to. How do I do this? My models looks like: class Thing(Model): read_groups = ManyToManyField('ASGGroup', related_name="thing_read", blank=True) class ASGGroup(Model): name = CharField(max_length=63, null=True) But what I'm seeing the m2m widget display is:

    Read the article

  • Accessing updated M2M fields in overriden save() in django's admin

    - by Jonathan
    I'd like to use the user updated values of a ManyToManyField in a model's overriden save() method when I save an instance in admin. It turns out that by design, django does not update the M2M field before calling save(), but only after the save() is complete as part of the form save... How can I access the new values of this field in the override save() ?

    Read the article

  • Django: Inherit Permssions from abstract models?

    - by lazerscience
    Is it possible to inherit permissions from an abstract model in Django? I can not really find anything about that. For me this doesn't work! class PublishBase(models.Model): class Meta: abstract = True get_latest_by = 'created' permissions = (('change_foreign_items', "Can change other user's items"),) EDIT: Not working means it fails silently. Permission is not created, as it wouldn't exist on the models inheriting from this class.

    Read the article

  • Django - problem with {% url facebook_xd_receiver %}

    - by Gaurav
    I'm using {% url facebook_xd_receiver %} in one of my HTML files. This works just fine when I run my project using the command python manage.py runserver But the same project stops running and gives me a "TemplateSyntaxError" at the line {% url facebook_xd_receiver %} Can anyone please tell me what could be the difference between the dev server run through the command line and the apache server. Is there anything I'm missing out on while configuring the Apache server? Or is it a Django problem?

    Read the article

  • django manage.py syncdb not working?

    - by Diego
    Trying to learn Django, I closed the shell and am getting this problem now when I call python manage.py syncdb, any idea what happened?: I've already set up a db. I have manage.py set up in the folder django_bookmarks. What's up here? Traceback (most recent call last): File "manage.py", line 2, in from django.core.management import execute_manager ImportError: No module named django.core.management my-computer:~/Django-1.1.1/django_bookmarks mycomp$ export PATH=/Users/mycomp/bin:$PATH my-computer:~/Django-1.1.1/django_bookmarks mycomp$ python manage.py syncdb Traceback (most recent call last): File "manage.py", line 2, in from django.core.management import execute_manager ImportError: No module named django.core.management my-computer:~/Django-1.1.1/django_bookmarks mycomp$

    Read the article

  • Django model manager didn't work with related object when I do aggregated query

    - by Satoru.Logic
    Hi, all. I'm having trouble doing an aggregation query on a many-to-many related field. Let's begin with my models: class SortedTagManager(models.Manager): use_for_related_fields = True def get_query_set(self): orig_query_set = super(SortedTagManager, self).get_query_set() # FIXME `used` is wrongly counted return orig_query_set.distinct().annotate( used=models.Count('users')).order_by('-used') class Tag(models.Model): content = models.CharField(max_length=32, unique=True) creator = models.ForeignKey(User, related_name='tags_i_created') users = models.ManyToManyField(User, through='TaggedNote', related_name='tags_i_used') objects_sorted_by_used = SortedTagManager() class TaggedNote(models.Model): """Association table of both (Tag , Note) and (Tag, User)""" note = models.ForeignKey(Note) # Note is what's tagged in my app tag = models.ForeignKey(Tag) tagged_by = models.ForeignKey(User) class Meta: unique_together = (('note', 'tag'),) However, the value of the aggregated field used is only correct when the model is queried directly: for t in Tag.objects.all(): print t.used # this works correctly for t in user.tags_i_used.all(): print t.used #prints n^2 when it should give n Would you please tell me what's wrong with it? Thanks in advance.

    Read the article

  • Putting a django login form on every page

    - by asciitaxi
    I'd like the login form (AuthenticationForm from django.contrib.auth) to appear on every page in my site if the user is not logged in. When the user logs in, they will be redirected to the same page. If there is an error, the error will be shown on the same page with the form. I suppose you'd need a context processor to provide the form to every template. But, then you'd also need every view to handle the posted form? Does this mean you need to create some middleware? I'm a bit lost. Is there an accepted way of doing this?

    Read the article

  • Django templates onchange data

    - by Hulk
    In the following code, i have a drop down box and a multi select box. My question is that using javascript and django .how will i changes the designation with changes in names from drop down box. <tr><td> name:</td><td><select id="name" name="name">{% for name in names %} <option value="{{name.id}}" {% for selected_id in names %}{% ifequal name.id selected_id %} {{ selected }} {% endifequal %} {% endfor %}>{{name.name}}</option>{% endfor %} </select> </td></tr> {% for desg in designation %} <tr><td><p>Topics:</td><td> <select id="desg" name="desg" multiple="multiple"> <option value="{{desg.id}}" >{{desg.desg}}</option> </select></p></td></tr> {% endfor %} Thanks..

    Read the article

  • Get the currently saved object in a view in Django

    - by mridang
    Hi, I has a Django view which is accessed through an AJAX call. It's a pretty simple one — all it does is simply pass the request to a form object and save the data. Here's a snippet from my view: form = AddSiteForm(request.user, request.POST) if form.is_valid(): obj = form.save(commit=False) obj.user = request.user obj.save() data['status'] = 'success' data['html'] = render_to_string('site.html', locals(), context_instance=RequestContext(request)) return HttpResponse(simplejson.dumps(data), mimetype='application/json') How do I get the currently saved object (including the internally generated id column) and pass it to the template? Any help guys? Mridang

    Read the article

  • Sort list of items in Django

    - by mridang
    Hi Guys, I have a Django view called change_priority. I'm posting a request to this view with a commas separated list of values which is basically the order of the items in my model. The data looks like this: 1,4,11,31,2,4,7 I have a model called Items which has two values - id and priority. Upon getting this post request, how can I set the priority of the Item depending upon the list order. So my data in the db would look like. 1,1 4,2 11,3 31,4 2,5 4,6 7,7 Thanks guys.

    Read the article

  • Cannot assign - must be a "UserProfile" instance

    - by webvulture
    I have a class UserProfile defined which takes the default user as a foreign key. Now another class A has a foreign key to UserProfile. So for saving any instance in class A, how do i give it the userprofile object. Also, does making a class UserProfile mean that class user is still used and class UserProfile is just some other table? I need to know this as I have to take care of the user profile creation, so I should know what gets stored where? -- Confused

    Read the article

  • Django Managers

    - by owca
    I have the following models code : from django.db import models from categories.models import Category class MusicManager(models.Manager): def get_query_set(self): return super(MusicManager, self).get_query_set().filter(category='Music') def count_music(self): return self.all().count() class SportManager(models.Manager): def get_query_set(self): return super(MusicManager, self).get_query_set().filter(category='Sport') class Event(models.Model): title = models.CharField(max_length=120) category = models.ForeignKey(Category) objects = models.Manager() music = MusicManager() sport = SportManager() Now by registering MusicManager() and SportManager() I am able to call Event.music.all() and Event.sport.all() queries. But how can I create Event.music.count() ? Should I call self.all() in count_music() function of MusicManager to query only on elements with 'Music' category or do I still need to filter through them in search for category first ?

    Read the article

  • django-admin formfield_for_* change default value per/depending on instance

    - by Nick Ma.
    Hi, I'm trying to change the default value of a foreignkey-formfield to set a Value of an other model depending on the logged in user. But I'm racking my brain on it... This: Changing ForeignKey’s defaults in admin site would an option to change the empty_label, but I need the default_value. #Now I tried the following without errors but it didn't had the desired effect: class EmployeeAdmin(admin.ModelAdmin): ... def formfield_for_foreignkey(self, db_field, request=None, **kwargs): formfields= super(EmployeeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) if request.user.is_superuser: return formfields if db_field.name == "company": #This is the RELEVANT LINE kwargs["initial"] = request.user.default_company return db_field.formfield(**kwargs) admin.site.register(Employee, EmployeeAdmin) ################################################################## # REMAINING Setups if someone would like to know it but i think # irrelevant concerning the problem ################################################################## from django.contrib.auth.models import User, UserManager class CompanyUser(User): ... objects = UserManager() company = models.ManyToManyField(Company) default_company= models.ForeignKey(Company, related_name='default_company') #I registered the CompanyUser instead of the standard User, # thats all up and working ... class Employee(models.Model): company = models.ForeignKey(Company) ... Hint: kwargs["default"] ... doesn't exist. Thanks in advance, Nick

    Read the article

  • Can django's auth_user.username be varchar(75)?

    - by perrierism
    Django's auth_user.username field is 30 characters. That means you can't have auth_user.username store an email address. If you want to have users authenticate based on their email address it would seem you have to do some wonky stuff like writing your own authentication backend which authenticates based on (email, password) instead of (username, password) and furthermore, figuring out what you're going to put in the username field since it is required and it is a primary key. Do you put a hash in there, do you try to put the id in there... bleh! Why should you have to write all this code and consider edge cases simply because username is too small for your (farily common) purposes? Is there anything wrong with running alter table on auth_user to make username be varchar(75) so it can fit an email? What does that break if anything?

    Read the article

  • Annotate over Multi-table Inheritance in Django

    - by user341584
    I have a base LoggedEvent model and a number of subclass models like follows: class LoggedEvent(models.Model): user = models.ForeignKey(User, blank=True, null=True) timestamp = models.DateTimeField(auto_now_add=True) class AuthEvent(LoggedEvent): good = models.BooleanField() username = models.CharField(max_length=12) class LDAPSearchEvent(LoggedEvent): type = models.CharField(max_length=12) query = models.CharField(max_length=24) class PRISearchEvent(LoggedEvent): type = models.CharField(max_length=12) query = models.CharField(max_length=24) Users generate these events as they do the related actions. I am attempting to generate a usage-report of how many of each event-type each user has caused in the last month. I am struggling with Django's ORM and while I am close I am running into a problem. Here is the query code: ef usage(request): # Calculate date range today = datetime.date.today() month_start = datetime.date(year=today.year, month=today.month - 1, day=1) month_end = datetime.date(year=today.year, month=today.month, day=1) - datetime.timedelta(days=1) # Search for how many LDAP events were generated per user, last month baseusage = User.objects.filter(loggedevent__timestamp__gte=month_start, loggedevent__timestamp__lte=month_end) ldapusage = baseusage.exclude(loggedevent__ldapsearchevent__id__lt=1).annotate(count=Count('loggedevent__pk')) authusage = baseusage.exclude(loggedevent__authevent__id__lt=1).annotate(count=Count('loggedevent__pk')) return render_to_response('usage.html', { 'ldapusage' : ldapusage, 'authusage' : authusage, }, context_instance=RequestContext(request)) Both ldapusage and authusage are both a list of users, each user annotated with a .count attribute which is supposed to represent how many particular events that user generated. However in both lists, the .count attributes are the same value. Infact the annotated 'count' is equal to how many events that user generated, regardless of type. So it would seem that my specific authusage = baseusage.exclude(loggedevent__authevent__id__lt=1) isn't excluding by subclass. I have tried id_lt=1, id_isnull=True, and others. Halp.

    Read the article

  • django forms doubt

    - by webvulture
    Here, I am a bit confused with forms in Django. I have information for the form(a poll i.e the poll question and options) coming from some db_table - table1 or say class1 in models. Now the vote from this poll is to be captured which is another model say class2. So, I am just getting confused with the whole flow of forms, here i think. How will the data be captured into the class2 table? I was trying something like this. def blah1()     get_data_from_db_table_1()     x = blah2Form()     render_to_response(blah.html,{...})

    Read the article

  • Django Caught an exception while rendering: No module named registration

    - by Arno Smit
    I seem to have run into a bit of an issue. I am busy creating an app, and over the last few weeks setup my server to use Git, mod_wsgi to host this app. Since deploying it, everything seems to be running smoothly however, I had to go through all my files and insert the absolute url of the project to make sure it works fine. on my local machine from registration.models import UserRegistration on server from myapp.registration.models import UserRegistration Am I doing something wrong? And this has also caused an issue for me where I cannot access my django admin interface. All i get is this: Caught an exception while rendering: No module named registration Exception Value: Caught an exception while rendering: No module named registration As far as I am concerned my app has all the relevant urls, but it does not seem to work. Thank you in advance

    Read the article

  • Can't set up image upload in Django

    - by culebrón
    I can't understand what's not working here: 1) settings MEDIA_ROOT = '/var/www/satel/media' MEDIA_URL = 'http://media.satel.culebron' ADMIN_MEDIA_PREFIX = '/media/' 2) models class Photo(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length = 200) desc = models.TextField(max_length = 1000) img = models.ImageField(upload_to = 'upload') 3) access rights: drwxr-xrwx 3 culebron culebron 4.0K 2010-04-14 21:13 media drwxr-xrwx 2 culebron culebron 4.0K 2010-04-14 19:04 upload 4) SQL: CREATE TABLE "photos_photo" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(200) NOT NULL, "desc" text NOT NULL, "img" varchar(100) NOT NULL ); 4) run Django test server as myself. 5) result: SuspiciousOperation at /admin/photos/author/add/ Attempted access to '/var/www/satel/upload/OpenStreetMap.png' denied. Not a PIL & jpeg issue, seems not to be access rights issue. But what's wrong?

    Read the article

  • Django shows too many warnings when deleting an object

    - by valya
    Hello! I have two models: class Account(models.Model): main_request = models.ForeignKey('JournalistRequest', related_name='main_request') key = models.CharField(_('Key'), max_length=100) class JournalistRequest(models.Model): account = models.ForeignKey(Account, blank=True, null=True) When I try to delete a JournalistRequest, It shows warning with a lot of nesting, like Are you sure you want to delete the selected ?????? ??? objects? All of the following objects and their related items will be deleted: Journalist Request: some request Account: some account Journalist Request: some request Account: some account Journalist Request: some request Account: some account Journalist Request: some request Account: some account Journalist Request: some request All accounts are the same one (ids are same), and all requests are the same one, so I think it becaues of a recursion. But I have no idea how to solve this problem in Django 1.1.1! Can you help me?

    Read the article

  • Help a Python newbie with a Django model inheritance problem

    - by Joshmaker
    I'm working on my first real Django project after years of PHP programming, and I am running into a problem with my models. First, I noticed that I was copying and pasting code between the models, and being a diligent OO programmer I decided to make a parent class that the other models could inherit from: class Common(model.Model): self.name = models.CharField(max_length=255) date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) def __unicode__(self): return self.name class Meta: abstract=True So far so good. Now all my other models extend "Common" and have names and dates like I want. However, I have a class for "Categories" were the name has to be unique. I assume there should be a relatively simple way for me to access the name attribute from Common and make it unique. However, the different methods I have tried to use have all failed. For example: class Category(Common): def __init__(self, *args, **kwargs): self.name.unique=True Spits up the error "Caught an exception while rendering: 'Category' object has no attribute 'name' Can someone point me in the right direction?

    Read the article

  • help with django and accented characters?

    - by Asinox
    Hi guys, i have a problem with my accented characters, Django admin save my data without encoding to something like "&aacute;" Example: if im trying a word like " Canción ", i would like to save in this way: Canci&oacute;n, and not Canción. im usign Sociable app: {% load sociable_tags %} {% get_sociable Facebook TwitThis Google MySpace del.icio.us YahooBuzz Live as sociable_links with url=object.get_absolute_url title=object.titulo %} {% for link in sociable_links %} <a href="{{ link.link }}"><img alt="{{ link.site }}" title="{{ link.site }}" src="{{ link.image }}" /></a> {% endfor %} But im getting error if my object.titulo (title of the article) have a accented word. aught KeyError while rendering: u'\xfa' Any idea ? i had in my SETTING: DEFAULT_CHARSET = 'utf-8' i had in my mysql database: utf8_general_ci thanks, sorry with my English

    Read the article

  • Decrease DB requests number from Django templates

    - by Andrew
    I publish discount offers for my city. Offer models are passed to template ( ~15 offers per page). Every offer has lot of items(every item has FK to it's offer), thus i have to make huge number of DB request from template. {% for item in offer.1 %} {{item.descr}} {{item.start_date}} {{item.price|floatformat}} {%if not item.tax_included %}{%trans "Without taxes"%}{%endif%} <a href="{{item.offer.wwwlink}}" >{%trans "Buy now!"%}</a> </div> <div class="clear"></div> {% endfor %} So there are ~200-400 DB requests per page, that's abnormal i expect. In django code it is possible to use select_related to prepopulate needed values, how can i decrease number of requests in template?

    Read the article

  • Django, making a page activate for a fixed time

    - by Hellnar
    Greetings I am hacking Django and trying to test something such as: Like woot.com , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item), Assume my urls for calling these items will be such: www.mysite.com/item/<number> my model for item: class Item(models.Model): item_name = models.CharField(max_length=30) price = models.FloatField() content = models.TextField() #keeps all the html content start_time = models.DateTimeField() end_time = models.DateTimeField() And my view for rendering this: def results(request, item_id): item = get_object_or_404(Item, pk=item_id) now = datetime.now() if item.start_time > now: #render and return some "not started yet" error templete elif item.end_time < now: #render and return some "item selling ended" error templete else: # render the real templete for selling this item What would be the efficient and clever model & templete for achieving this ?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >