Re: Sending data to the server
Do you have CSRF protection enabled? https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ It will 403 POST requests unless they have the right token. Jim On Sun, Mar 25, 2012 at 11:24 PM, drk wrote: > Hi, so I have a application that works offline (with localStorage), > and now I'm trying to get it to work in a server. > > I'm having a problem sending the data to server, I'm using jquery: > > $.ajax({ > > type: 'POST', > url: 'http://mysite.aa/logout/', > data: JSON.stringify( stuff ), > contentType: 'text/plain; charset=utf-8', > complete: function() { console.log('complete'); } > }); > > and I get a 403 error. > > In chrome's console: > > POST http://mysite.aa/logout/ 403 (FORBIDDEN) > XHR finished loading: "http://myserver.aa/logout/"; > > In server: > [25/Mar/2012 17:20:43] "POST /logout/ HTTP/1.1" 403 2282 > > > Any ideas? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Custom option for Model Meta Options
Hello, in my App I would like some Models to accept some custom Meta options like this: class MyModel(models.Model) name = models.CharField(...) other = models.CharField(...) more = models.CharField(...) class Meta: db_table = "my_table" custom_option = True It would be quite easy to accomplish this by paching the django source. However I'd prefere to do this by subclassing. How to do this? Best regards Roman Klesel -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Template Error: Invalid block tag: 'endblock', expected 'empty' or 'endfor'
On 25 March 2012 11:56, Homer wrote: > I tried to create an index webpage but Django told me I had a template > error: > > Invalid block tag: 'endblock', expected 'empty' or 'endfor' > > Here is the code of index.html: > > {% extends "base.html" %} > > {% block title %}Home{% endblock %} > {% block content %} > > Welcome to So Easy! 学中文 > > Showcase > > > {% for item in item_list|slice:":3" %} > > {{ item.name }} > {% if item.photo_set.count %} > > {% else %} > No Photos (yet) > {% endif %} > > > <% endfor %> This line should be {% endfor %}. > > > View the full list; > > {% endblock %} #Error Here > {% block footer %} > > I hope someone can help me. Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/Dn_zBeC7tnYJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Template Error: Invalid block tag: 'endblock', expected 'empty' or 'endfor'
On 25 March 2012 11:56, Homer wrote: > I tried to create an index webpage but Django told me I had a template > error: > > Invalid block tag: 'endblock', expected 'empty' or 'endfor' > > Here is the code of index.html: > > {% extends "base.html" %} > > {% block title %}Home{% endblock %} > {% block content %} > > Welcome to So Easy! 学中文 > > Showcase > > > {% for item in item_list|slice:":3" %} > > {{ item.name }} > {% if item.photo_set.count %} > > {% else %} > No Photos (yet) > {% endif %} > > > <% endfor %> This line should be {% endfor %}. > > > View the full list; > > {% endblock %} #Error Here > {% block footer %} > > I hope someone can help me. Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/Dn_zBeC7tnYJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Multiple Choice Quiz
Ok. Let me send you a gist about how I achieved mine to give you an idea. On Sat, Mar 24, 2012 at 4:46 PM, jbr3 wrote: > Babatunde, > > Yes, that's basically the same idea. The questions would all be on the > same page, however, and I wouldn't incorporate the time limit. But, > that's mostly what I was thinking of. > > On Mar 24, 3:08 am, Babatunde Akinyanmi wrote: > > Hi jbr3, > > Check scrabala.com > > Is it similar to what you are working on? > > > > On 3/23/12, jbr3 wrote: > > > > > > > > > Hi again, > > > > > I've been trying to figure this out for awhile, but to no avail. I'll > > > try to list the problems I've had in understanding it. > > > > > 1. I'm not sure what the forms.py file should look like. > > > > > Going by Shawn's model, would it be something like: > > > > > " class GuessForm(ModelForm): > > > class Meta: > > > model= Guess > > > exclude = ('user') " > > > > > This gives me a dropdown list of possible answers, but no form changes > > > I've tried to make give me multiple radio buttons or multiple > > > checkboxes. Have I selected the wrong model to make the modelform > > > from ? > > > > > 2. I don't completely understand the concept of using Booleans. I've > > > added admin functionality to the app so I can add questions and > > > potential answers as well as select (using a checkbox) the correct > > > response. Based on the model Shawn provided, selecting one of the > > > checkboxes generated in admin makes that choice true and the others > > > false. The user's answer needs to be compared against these, but I > > > don't understand how I would achieve that. I assume I'm supposed to > > > set this up in the form, but I can't get the radio buttons or > > > checkboxes to work there. I can successfully submit an answer from the > > > dropdown, but I still have no idea how it would be compared to the > > > stored boolean value. Do I have to write more code for this ? And what > > > would the best way be to retrieve it ? > > > > > Also, in the examples I've seen, BooleanField() in forms involves > > > creating a list of choices in the form. But it doesn't seem like I > > > would need such a thing if I'm just using radio buttons whose value > > > will be checked against a changing option for each question. Yet I > > > can't really see how an alternative approach would work. > > > > > 3. I don't know what the template should look like. It seems like I > > > should be mixing the form fields with data passed directly from the > > > model by using views. In my view, I've set > > > "Question.objects.get(id=1)" to a variable. I've passed that to the > > > template. But I've also used "{{ form.as_p }}". That gives me the > > > possible answers that had been entered in the admin in the template. > > > But, the answers aren't generated as radio buttons with text next to > > > them. It seems like I would have to pass the actual text of the > > > answers using views (setting "variable.answer_set.all() to another > > > variable and then passing it to the template) and then generate radio > > > buttons some other way. When I generated the buttons in the template, > > > though, the submission failed. I don't see how these could be checked > > > against the boolean value stored for the right answer. And, like I > > > said, I can't figure out how to make them work properly with the > > > form. > > > > > I know I've asked this already, but is it possible for anyone to show > > > some sample code so I can understand how this should be done using > > > Shawn's models. I've been trying to get this for awhile now, but I > > > still don't really understand it. I know there are about fifty > > > different questions here, but if anyone could help out in any way it > > > would be appreciated. > > > > > Thanks > > > > > On Mar 14, 11:36 pm, jbr3 wrote: > > >> Can anyone help me with some questions I still have about this ? I > > >> haven't had much experience with web programming, so trying to > > >> understand this is kind of challenging. > > > > >> 1. I created the models Shawn suggested. And I'm now able to add a > > >> question and possible answers to it in the admin area. Each possible > > >> answer has a checkbox next to it with the "Correct" label from the > > >> model. Does setting the correct response require anything more than > > >> selecting the appropriate checkbox and saving the question ? > > > > >> 2. I still don't understand how I'm supposed to combine these three > > >> models together in order to get the right output for the user. I've > > >> been trying different approaches in views.py, forms.py and my > > >> template. But I can't really figure out how this should be set up. I > > >> don't like to keep asking for such direct examples. > > >> But would anyone be able to provide kind of an abstract view based on > > >> the model Shawn provided. > > > > >> On Mar 11, 5:16 pm, jbr3 wrote: > > > > >> > Thanks for responding Shawn. I guess I was thinking that if I
Re: Multiple Choice Quiz
jbr3, https://gist.github.com/2204408 The code is most likely buggy and might be insecure because I'm not really sure if hackers can use radio buttons to submit malicious stuff. The idea is using the model structure Shawn gave. I created a custom form class which extracts some Question instances. Since Answers foreignKey to Questions, the answers linked to each question can be retrieved. There is a function that takes these Questions and its related Answers and then outputs the html for the form such that the Answers are displayed as radio buttons. If the custom form comes in with data from the request, the customForm determines how many of them are correct. If you go through the code you would see how the boolean in Answer can be used to determine the correct answer. We can talk about my fee later :D ;) If you still have issues let me know. On Mon, Mar 26, 2012 at 11:42 AM, Babatunde Akinyanmi wrote: > Ok. Let me send you a gist about how I achieved mine to give you an idea. > > > On Sat, Mar 24, 2012 at 4:46 PM, jbr3 wrote: > >> Babatunde, >> >> Yes, that's basically the same idea. The questions would all be on the >> same page, however, and I wouldn't incorporate the time limit. But, >> that's mostly what I was thinking of. >> >> On Mar 24, 3:08 am, Babatunde Akinyanmi wrote: >> > Hi jbr3, >> > Check scrabala.com >> > Is it similar to what you are working on? >> > >> > On 3/23/12, jbr3 wrote: >> > >> > >> > >> > > Hi again, >> > >> > > I've been trying to figure this out for awhile, but to no avail. I'll >> > > try to list the problems I've had in understanding it. >> > >> > > 1. I'm not sure what the forms.py file should look like. >> > >> > > Going by Shawn's model, would it be something like: >> > >> > > " class GuessForm(ModelForm): >> > > class Meta: >> > > model= Guess >> > > exclude = ('user') " >> > >> > > This gives me a dropdown list of possible answers, but no form changes >> > > I've tried to make give me multiple radio buttons or multiple >> > > checkboxes. Have I selected the wrong model to make the modelform >> > > from ? >> > >> > > 2. I don't completely understand the concept of using Booleans. I've >> > > added admin functionality to the app so I can add questions and >> > > potential answers as well as select (using a checkbox) the correct >> > > response. Based on the model Shawn provided, selecting one of the >> > > checkboxes generated in admin makes that choice true and the others >> > > false. The user's answer needs to be compared against these, but I >> > > don't understand how I would achieve that. I assume I'm supposed to >> > > set this up in the form, but I can't get the radio buttons or >> > > checkboxes to work there. I can successfully submit an answer from the >> > > dropdown, but I still have no idea how it would be compared to the >> > > stored boolean value. Do I have to write more code for this ? And what >> > > would the best way be to retrieve it ? >> > >> > > Also, in the examples I've seen, BooleanField() in forms involves >> > > creating a list of choices in the form. But it doesn't seem like I >> > > would need such a thing if I'm just using radio buttons whose value >> > > will be checked against a changing option for each question. Yet I >> > > can't really see how an alternative approach would work. >> > >> > > 3. I don't know what the template should look like. It seems like I >> > > should be mixing the form fields with data passed directly from the >> > > model by using views. In my view, I've set >> > > "Question.objects.get(id=1)" to a variable. I've passed that to the >> > > template. But I've also used "{{ form.as_p }}". That gives me the >> > > possible answers that had been entered in the admin in the template. >> > > But, the answers aren't generated as radio buttons with text next to >> > > them. It seems like I would have to pass the actual text of the >> > > answers using views (setting "variable.answer_set.all() to another >> > > variable and then passing it to the template) and then generate radio >> > > buttons some other way. When I generated the buttons in the template, >> > > though, the submission failed. I don't see how these could be checked >> > > against the boolean value stored for the right answer. And, like I >> > > said, I can't figure out how to make them work properly with the >> > > form. >> > >> > > I know I've asked this already, but is it possible for anyone to show >> > > some sample code so I can understand how this should be done using >> > > Shawn's models. I've been trying to get this for awhile now, but I >> > > still don't really understand it. I know there are about fifty >> > > different questions here, but if anyone could help out in any way it >> > > would be appreciated. >> > >> > > Thanks >> > >> > > On Mar 14, 11:36 pm, jbr3 wrote: >> > >> Can anyone help me with some questions I still have about this ? I >> > >> haven't had much experience with web programming, so trying t
De-serialization of ManyToManyField
Hi, I have searched high and low to an answer to this, but have been unable too turn anything up. Apologies if I have overlooked an answer or explanation elsewhere. I have set up a very simple model as follows: --- from django.db import models class TestManager(models.Manager): def get_by_natural_key(self, name): return self.get(name=name,) class Test(models.Model): name = models.CharField(max_length = 100, unique = True) date = models.DateField() def __unicode__(self): return self.name def natural_key(self): return (self.name) class InstanceManager(models.Manager): def get_by_natural_key(self, name): return self.get(name=name,) class Instance(models.Model): name = models.CharField(max_length = 100, unique = True) test = models.ManyToManyField(Test) date = models.DateField() def __unicode__(self): return self.name def natural_key(self): return (self.name) --- looking at the admin interface I am able to add a couple of 'tests' (test 1 and test 2). I am then able to add an instance which is linked to both test 1 and test 2. If I dump the data to YAML format then I get the following (for the two tables in question): --- - fields: {date: 2012-03-26, name: test 1} model: TempDB.test pk: 1 - fields: {date: 2012-03-26, name: test 2} model: TempDB.test pk: 2 - fields: date: 2012-03-26 name: Instance 1 test: [test 1, test 2] model: TempDB.instance pk: 1 --- This is roughly what I would expect to see, although the documentation does not explicitly state that a manytomany serialization will be a multi-element list, it seems to be a reasonable assumption. When I try to perform a loaddata with this output (and after manually deleting the tables from the admin interface, to be sure). I get the following error: Problem installing fixture '/home//workspace/THMDB/THMDB/TempDB/ fixtures/test.yaml': Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/ django/core/management/commands/loaddata.py", line 190, in handle for obj in objects: File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/ django/core/serializers/pyyaml.py", line 62, in Deserializer raise DeserializationError(e) DeserializationError: [u"'test 1' value must be an integer."] What exactly have I done wrong? I suspect I have made an error in defining the managers. I have defined two as I planned to link too instances from another table. I left in the definition in case it is the cause of the error. However it still does the same thing if I comment it out. I am running Django 1.4 on python 2.7 under Ubuntu 11.10. Many thanks for your help. Stephen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Tweepy Status Error
In the example given in doc of tweepy, the process_status is a user defined method. You have to define this method. Its just a reference given. Define a method process_status and do whatever you want to do with status. On Mar 26, 3:57 am, coded kid wrote: > Hi guys, I been trying to iterate over status, but I’m getting this > error: > > Traceback : > File “”, line 2, in > NameError: name ‘process_status’ is not defined. > > Below is the codes: > > from tweepy import Cursor > for status in Cursor(api.user_timeline).items(): > process_status(status) > > What I’m I doing wrong? Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Pip install matplotlib error with virtualenv
On 23-03-12 22:01, darwin_tech wrote: Yes, that is true. I set the virtualenv with --no-site-packages as I want a reproducible environment for my Django project. This should not mean that I cannot install matplotlib within the virtualenv though, surely? You can install matplotlib just fine in your virtualenv, but with one prerequisite: all necessary libraries and header files must be available for pip to be able to compile matplotlib. This compiling-and-grabbing-headers stuff is already handled for you by your OS and now you'll have to do it yourself. Which is fine, but it *does* mean you must have all xyz-devel packages installed. An alternative is to keep your global python clean and only install specific packages with your OS that are best handled by the OS. Don't "pip install" other stuff by hand. Reinout -- Reinout van Reeshttp://reinout.vanrees.org/ rein...@vanrees.org http://www.nelen-schuurmans.nl/ "If you're not sure what to do, make something. -- Paul Graham" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: philosophy behind sites and applications in Django
On 26-03-12 02:21, Jojo wrote: Hi guys, I'm new in Django (I started with the 1.3 and now I'm playing with the 1.4) and I'd like to understand better the phylosophy behind the concepts of sites and applications. Ok a site can contain multiple applications and an application can live in many sites, that's simple. Now. For me a site is like a "container" of applications and every application accomplish a particular job just like manage polls, articles and so on. But a site must have its own graphic style, and in particular common parts, just like user management. How do you handle these "trasversal" (common) components? For example, is it possible to define a css at site level? How to deal with user management and other commont funcionalities? You're right, a site is a container of applications and an application should do one thing and one thing only. Normally, you don't want your site to contain applications and at the same time have those applications inherit from your site's main template or so. But... django sticks all the templates/ and static/ directories of all apps and sites together. So nothing stops you from sticking a very basic base template in every app ("yourapp/templates/base.html") with just a sidebar and main content block or so. You can have your apps use that. In your site, you provide the real "yoursite/templates/base.html", which will win because your site is higher up in the INSTALLED_APPS list. Stuff that one full with the real layout and css, but keep providing the sidebar and content block (or whatever you need). Alternative: just make templates in the apps and customize them in the site. Not as nice imho. ALternative: start a base UI app that just provides a layout. Use that in the apps. Reinout -- Reinout van Reeshttp://reinout.vanrees.org/ rein...@vanrees.org http://www.nelen-schuurmans.nl/ "If you're not sure what to do, make something. -- Paul Graham" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Much the same code, different businesses
Hi all, I'm wanting the same code to run many fairly simple, near-identical websites. That's the bottom line. I've had a look through the group archives and found a couple of hints. My planned application serves small grocery businesses taking orders and making weekly home deliveries for their customers. It is planned to serve a large number of small businesses (<10 staff each, no of businesses potentially in the 1000s). They are all small retailers with a need for their own domain name, their own "look", their own (broadly similar but different) data, their own Admin console and their own stationery (mainly invoicing.) But the Django code running each will be near-identical. Questions: Is there one, and only one, obvious way to do it in Django? What is that way? Databases (PostgreSQL.) Would you: (i) separate the database for each business (ii) use a StoreId in all queries or (iii) implement row-level permissions to restrict access to data? Any other comments? Best wishes, Nick -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: myproject/wsgi.py vs. myproject.wsgi?
On 25-03-12 08:04, Micky Hulse wrote: Hello, This is is probably a silly question, but... I just installed a fresh copy ofDjango 1.4 (mod_wsgi 3.3/Python 2.7) on my WebFaction server. In 1.3, the command startproject (IIRC) generated a myproject.wsgi that lived next to myporject folder. In the 1.4 installer, the wsgi file is no longer generated and there's the new myproject/wsgi.py file. I have read the docs (and Googled around a little bit) but I don't fully understand wsgi.py does. In 1.3, there was no wsgi file. So either you added it yourself or webfaction automatically adds it. 1.4 started adding that wsgi.py file. It should be a drop-in replacement for the one you have now, basically. (Only thing to watch out for: wsgi.py hardcodes settings.py, so if you want to use a productionsettings.py or so you should take a good hard look). Reinout -- Reinout van Reeshttp://reinout.vanrees.org/ rein...@vanrees.org http://www.nelen-schuurmans.nl/ "If you're not sure what to do, make something. -- Paul Graham" -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Custom option for Model Meta Options
On Mar 26, 12:26 pm, Roman Klesel wrote: > Hello, > > in my App I would like some Models to accept some custom Meta options like > this: > > class MyModel(models.Model) > > name = models.CharField(...) > other = models.CharField(...) > more = models.CharField(...) > > class Meta: > > db_table = "my_table" > custom_option = True I think there are three steps to do this: 1. Create a subclass of models.base.ModelBase (called OwnModelBase for this example) 2. Override methods you want to customize. 3. Model definition: class MyModel(models.Model): __metaclass__ = OwnModelBase ... I think that should work, although I haven't tested this. For examples transmeta has an overridden metaclass, so you can check what they do [http://code.google.com/p/django-transmeta/source/browse/trunk/ transmeta/__init__.py]. - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to adjust grid in Django Admin Forms
I've just created a model in Django and want to use the admin form to enter information for it. The problem I'm having is that my field names are so long that they overlap the edit boxes where their values are to be entered. If one follows the tutorial in the Django website, it's as if the label "Question:" overlapped the edit box where one was supposed to enter a question. The file "fieldset.html" in the /admin/includes sub-directory seems to have the relevant code: {% if fieldset.name %}{{ fieldset.name }} - Foo Test{% endif %} {% for line in fieldset %} {% for field in line %} {{ field.label_tag }}{{ field.field }} {% endfor %} {% endfor %} What I can't figure out is how to allocate more space to {{ field.label_tag }}, so that it is not covered up by {{ field.label_tag }}. Any help would be appreciated. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to adjust grid in Django Admin Forms
On Mar 26, 4:53 pm, Steven wrote: > I've just created a model in Django and want to use the admin form to > enter information for it. The problem I'm having is that my field > names are so long that they overlap the edit boxes where their values > are to be entered. > > If one follows the tutorial in the Django website, it's as if the > label "Question:" overlapped the edit box where one was supposed to > enter a question. > > The file "fieldset.html" in the /admin/includes sub-directory seems to > have the relevant code: > > > {% if fieldset.name %}{{ fieldset.name }} - Foo Test{% > endif %} > {% for line in fieldset %} > > {% for field in line %} > > {{ field.label_tag }}{{ field.field }} > > {% endfor %} > > {% endfor %} > > > What I can't figure out is how to allocate more space to > {{ field.label_tag }}, so that it is not covered up by > {{ field.label_tag }}. > > Any help would be appreciated. Using firebug I spotted this css for the label tag (Django 1.2 installation, might be different in more recent versions): .aligned label { display: block; float: left; padding: 3px 10px 0 0; width: 8em; } So, you would probably want to override that (the width, especially) in a custom css file. The documentation should contain the details of how to do that. https://docs.djangoproject.com/en/dev/ref/contrib/admin/ - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Sending data to the server
Yea, that was it. Also changing the url to just '/logout' Thanks! I'm having other problem now, the data that is getting sent to the javascript code from the server is json data, but the quote symbol " is returned as " and so I get an error when trying to parse it. Segunda-feira, 26 de Março de 2012 08h16min49s UTC+1, jim escreveu: > > Do you have CSRF protection enabled? > > https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ > > It will 403 POST requests unless they have the right token. > > Jim > > On Sun, Mar 25, 2012 at 11:24 PM, drk wrote: > > Hi, so I have a application that works offline (with localStorage), > > and now I'm trying to get it to work in a server. > > > > I'm having a problem sending the data to server, I'm using jquery: > > > > $.ajax({ > > > >type: 'POST', > >url: 'http://mysite.aa/logout/', > >data: JSON.stringify( stuff ), > >contentType: 'text/plain; charset=utf-8', > >complete: function() { console.log('complete'); } > > }); > > > > and I get a 403 error. > > > > In chrome's console: > > > > POST http://mysite.aa/logout/ 403 (FORBIDDEN) > > XHR finished loading: "http://myserver.aa/logout/"; > > > > In server: > > [25/Mar/2012 17:20:43] "POST /logout/ HTTP/1.1" 403 2282 > > > > > > Any ideas? > > > > -- > > You received this message because you are subscribed to the Google > Groups "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/7wacnIh7RvkJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Sending data to the server
Just to rephrase it, I'm setting the data through a variable in a django template, maybe that's not the best way to do it, I guess. Segunda-feira, 26 de Março de 2012 16h23min15s UTC+1, drk escreveu: > > Yea, that was it. > Also changing the url to just '/logout' > > Thanks! > > > I'm having other problem now, the data that is getting sent to the > javascript code from the server is json data, but the quote symbol " is > returned as " > and so I get an error when trying to parse it. > > > Segunda-feira, 26 de Março de 2012 08h16min49s UTC+1, jim escreveu: >> >> Do you have CSRF protection enabled? >> >> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ >> >> It will 403 POST requests unless they have the right token. >> >> Jim >> >> On Sun, Mar 25, 2012 at 11:24 PM, drk wrote: >> > Hi, so I have a application that works offline (with localStorage), >> > and now I'm trying to get it to work in a server. >> > >> > I'm having a problem sending the data to server, I'm using jquery: >> > >> > $.ajax({ >> > >> >type: 'POST', >> >url: 'http://mysite.aa/logout/', >> >data: JSON.stringify( stuff ), >> >contentType: 'text/plain; charset=utf-8', >> >complete: function() { console.log('complete'); } >> > }); >> > >> > and I get a 403 error. >> > >> > In chrome's console: >> > >> > POST http://mysite.aa/logout/ 403 (FORBIDDEN) >> > XHR finished loading: "http://myserver.aa/logout/"; >> > >> > In server: >> > [25/Mar/2012 17:20:43] "POST /logout/ HTTP/1.1" 403 2282 >> > >> > >> > Any ideas? >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "Django users" group. >> > To post to this group, send email to django-users@googlegroups.com. >> > To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qS2bKnHERdYJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to adjust grid in Django Admin Forms
I tried changing width from 8em to 16em in /usr/local/lib/python2.7/ dist-packages/django/contrib/admin/static/admin/css/forms.css in the two places where it appeared: .aligned label{ display: bloack; padding: 3px 10px 0 0; float: left; width: 8em; } and .inline-group .aligned-label{ width: 8em; } but to no avail. Is there someplace else I should be looking?? On Mar 26, 10:21 am, akaariai wrote: > On Mar 26, 4:53 pm, Steven wrote: > > > > > > > > > > > I've just created a model in Django and want to use the admin form to > > enter information for it. The problem I'm having is that my field > > names are so long that they overlap the edit boxes where their values > > are to be entered. > > > If one follows the tutorial in the Django website, it's as if the > > label "Question:" overlapped the edit box where one was supposed to > > enter a question. > > > The file "fieldset.html" in the /admin/includes sub-directory seems to > > have the relevant code: > > > > > {% if fieldset.name %}{{ fieldset.name }} - Foo Test{% > > endif %} > > {% for line in fieldset %} > > > > {% for field in line %} > > > > {{ field.label_tag }}{{ field.field }} > > > > {% endfor %} > > > > {% endfor %} > > > > > What I can't figure out is how to allocate more space to > > {{ field.label_tag }}, so that it is not covered up by > > {{ field.label_tag }}. > > > Any help would be appreciated. > > Using firebug I spotted this css for the label tag (Django 1.2 > installation, might be different in more recent versions): > .aligned label { > display: block; > float: left; > padding: 3px 10px 0 0; > width: 8em; > > } > > So, you would probably want to override that (the width, especially) > in a custom css file. The documentation should contain the details of > how to do that.https://docs.djangoproject.com/en/dev/ref/contrib/admin/ > > - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Authentication and Modeling question.
I'm working on a rewrite of an app that has three categories of users and I'm wondering about the best way to link them to the authentication system: In-House Staff. Contractors Customers who interact via the app. The in-house staff model doesn't store any address info. Contractor and Customer have some common attributes (address, phone number, email, etc.) but they have completely different relationships to the rest of the system. In the current version I have discrete models for each type and I manually maintain a link to the equivalent of the user profile table. But I don't have model inheritance available in the current system. My question is, do you have any general advice for this and how would you link it to the existing Auth system, or is there a 3rd party auth system that you'd recommend I look at. Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Multiple Choice Quiz
Thank you for taking the time to help Babatunde; it's very much appreciated. On Mar 26, 7:00 am, Babatunde Akinyanmi wrote: > jbr3,https://gist.github.com/2204408 > The code is most likely buggy and might be insecure because I'm not really > sure if hackers can use radio buttons to submit malicious stuff. > The idea is using the model structure Shawn gave. I created a custom form > class which extracts some Question instances. Since Answers foreignKey to > Questions, the answers linked to each question can be retrieved. There is a > function that takes these Questions and its related Answers and then > outputs the html for the form such that the Answers are displayed as radio > buttons. If the custom form comes in with data from the request, the > customForm determines how many of them are correct. If you go through the > code you would see how the boolean in Answer can be used to determine the > correct answer. > We can talk about my fee later :D ;) > If you still have issues let me know. > > On Mon, Mar 26, 2012 at 11:42 AM, Babatunde Akinyanmi > wrote: > > > Ok. Let me send you a gist about how I achieved mine to give you an idea. > > > On Sat, Mar 24, 2012 at 4:46 PM, jbr3 wrote: > > >> Babatunde, > > >> Yes, that's basically the same idea. The questions would all be on the > >> same page, however, and I wouldn't incorporate the time limit. But, > >> that's mostly what I was thinking of. > > >> On Mar 24, 3:08 am, Babatunde Akinyanmi wrote: > >> > Hi jbr3, > >> > Check scrabala.com > >> > Is it similar to what you are working on? > > >> > On 3/23/12, jbr3 wrote: > > >> > > Hi again, > > >> > > I've been trying to figure this out for awhile, but to no avail. I'll > >> > > try to list the problems I've had in understanding it. > > >> > > 1. I'm not sure what the forms.py file should look like. > > >> > > Going by Shawn's model, would it be something like: > > >> > > " class GuessForm(ModelForm): > >> > > class Meta: > >> > > model= Guess > >> > > exclude = ('user') " > > >> > > This gives me a dropdown list of possible answers, but no form changes > >> > > I've tried to make give me multiple radio buttons or multiple > >> > > checkboxes. Have I selected the wrong model to make the modelform > >> > > from ? > > >> > > 2. I don't completely understand the concept of using Booleans. I've > >> > > added admin functionality to the app so I can add questions and > >> > > potential answers as well as select (using a checkbox) the correct > >> > > response. Based on the model Shawn provided, selecting one of the > >> > > checkboxes generated in admin makes that choice true and the others > >> > > false. The user's answer needs to be compared against these, but I > >> > > don't understand how I would achieve that. I assume I'm supposed to > >> > > set this up in the form, but I can't get the radio buttons or > >> > > checkboxes to work there. I can successfully submit an answer from the > >> > > dropdown, but I still have no idea how it would be compared to the > >> > > stored boolean value. Do I have to write more code for this ? And what > >> > > would the best way be to retrieve it ? > > >> > > Also, in the examples I've seen, BooleanField() in forms involves > >> > > creating a list of choices in the form. But it doesn't seem like I > >> > > would need such a thing if I'm just using radio buttons whose value > >> > > will be checked against a changing option for each question. Yet I > >> > > can't really see how an alternative approach would work. > > >> > > 3. I don't know what the template should look like. It seems like I > >> > > should be mixing the form fields with data passed directly from the > >> > > model by using views. In my view, I've set > >> > > "Question.objects.get(id=1)" to a variable. I've passed that to the > >> > > template. But I've also used "{{ form.as_p }}". That gives me the > >> > > possible answers that had been entered in the admin in the template. > >> > > But, the answers aren't generated as radio buttons with text next to > >> > > them. It seems like I would have to pass the actual text of the > >> > > answers using views (setting "variable.answer_set.all() to another > >> > > variable and then passing it to the template) and then generate radio > >> > > buttons some other way. When I generated the buttons in the template, > >> > > though, the submission failed. I don't see how these could be checked > >> > > against the boolean value stored for the right answer. And, like I > >> > > said, I can't figure out how to make them work properly with the > >> > > form. > > >> > > I know I've asked this already, but is it possible for anyone to show > >> > > some sample code so I can understand how this should be done using > >> > > Shawn's models. I've been trying to get this for awhile now, but I > >> > > still don't really understand it. I know there are about fifty > >> > > different questions here, but if anyone could help out in any way it > >
Re: Adding link to admin page
On Mar 25, 3:29 pm, Larry Martell wrote: > I have a client that has an app built with django. On every page of > their app is a link to their admin site. They tell me the admin site > is generated entirely by django, and they've never customized it > before. On the very first line of the admin page it says: > > Django administration Welcome, admin. Change password / Log out > > They want me to add a link to that line, to the left of "Django > administration" that will take them back to the page they were on when > they clicked on the link to get them to the admin site. > > So I have 2 issues here: > > 1) How do I override that line to add the link? It appears that page > is generated by contrib/admin/templates/admin/base.html, and I tried > to override it by following the directions > athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., > but whatever I do seems to have no effect. > > 2) How can I get the link of the page of the app they came from? It's > not simply just going back one page, as they could have navigated all > over the place of the admin site before clicking the "Back to app" > link. > > Thanks! > -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Adding link to admin page
On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: On Mar 25, 3:29 pm, Larry Martell wrote: I have a client that has an app built with django. On every page of their app is a link to their admin site. They tell me the admin site is generated entirely by django, and they've never customized it before. On the very first line of the admin page it says: Django administration Welcome, admin. Change password / Log out They want me to add a link to that line, to the left of "Django administration" that will take them back to the page they were on when they clicked on the link to get them to the admin site. So I have 2 issues here: 1) How do I override that line to add the link? It appears that page is generated by contrib/admin/templates/admin/base.html, and I tried to override it by following the directions athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., but whatever I do seems to have no effect. 2) How can I get the link of the page of the app they came from? It's not simply just going back one page, as they could have navigated all over the place of the admin site before clicking the "Back to app" link. Thanks! -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders Basically, django uses the first template it finds so if it finds the "real" one in site-packages first, it stops looking. Try reversing the sequence of loaders in your settings.py Mike -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: myproject/wsgi.py vs. myproject.wsgi?
On Mon, Mar 26, 2012 at 5:14 AM, Reinout van Rees wrote: > In 1.3, there was no wsgi file. So either you added it yourself or > webfaction automatically adds it. > 1.4 started adding that wsgi.py file. It should be a drop-in replacement for > the one you have now, basically. > (Only thing to watch out for: wsgi.py hardcodes settings.py, so if you want > to use a productionsettings.py or so you should take a good hard look). Thank you Reinout! I really appreciate the explanation. :) I will use the wsgi.py as a replacement and see how it goes. Much appreciated. Have a great day! Cheers, Micky -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Adding link to admin page
On Mon, Mar 26, 2012 at 4:37 PM, Mike Dewhirst wrote: > On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: >> >> On Mar 25, 3:29 pm, Larry Martell wrote: >>> >>> I have a client that has an app built with django. On every page of >>> their app is a link to their admin site. They tell me the admin site >>> is generated entirely by django, and they've never customized it >>> before. On the very first line of the admin page it says: >>> >>> Django administration Welcome, admin. Change password / Log out >>> >>> They want me to add a link to that line, to the left of "Django >>> administration" that will take them back to the page they were on when >>> they clicked on the link to get them to the admin site. >>> >>> So I have 2 issues here: >>> >>> 1) How do I override that line to add the link? It appears that page >>> is generated by contrib/admin/templates/admin/base.html, and I tried >>> to override it by following the directions >>> athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., >>> but whatever I do seems to have no effect. >>> >>> 2) How can I get the link of the page of the app they came from? It's >>> not simply just going back one page, as they could have navigated all >>> over the place of the admin site before clicking the "Back to app" >>> link. >>> >>> Thanks! >>> -larry >> >> Is there anyone that can provide some assistance with overriding >> base_site.html? I copied django/contrib/admin/templates/admin/ >> base_site.html to my projects's templates/admin dir, but changes to it >> are not getting picked up. I also tried adding that to TEMPLATE_DIRS >> (there was nothing in it before). In urlpatterns I have: (r'^admin/', >> include(admin.site.urls)) - does that need to change? > > > Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders > > Basically, django uses the first template it finds so if it finds the "real" > one in site-packages first, it stops looking. Try reversing the sequence of > loaders in your settings.py Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this: TEMPLATE_LOADERS = ( 'appmngr.load_app_template', 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', ) Where the first entry is a custom template loader that doesn't appear to know how to load something from my apps templates/admin dir. Are the other 2 entries 'standard' loaders that would look for my base_site.html (since I put full path to it in TEMPLATE_DIRS)? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Much the same code, different businesses
There are a few choices that I'm familiar with. 1) Create a separate project/settings file for each of your stores, overriding templates as needed by placing assigning a template path for the project. I think this is pretty much the recommended way to do things, especially if the number of sites are reasonably small. It offers great data isolation (using a different database for each), and it allows you to use all kinds of django apps and plugins. For mass hosting, this is going to require more resources since you'll have workers for each site rather than a shared pool of workers. 2) Do some 'strange things', such as changing database or schema on a per-request basis using threadlocals and a middleware. This offers much of the capability of 1, but there may be compatibility issues (module level caching for example) and tricky foreignkey restrictions.http://tidbids.posterous.com/saas-with-django-and-postgresql That post, and some of the comments will probably be of interest to you. 2) Do your own multi-tenant user setup. There isn't anything built in for this, and as a result you lose a lot of the built in functionality like the admin as well as any hope of using user aware third-party apps. This is the way I ended up going. We use a custom template loader/middleware to check for site specific templates, site specific caching, and a custom siteuser/site framework. All data is stored in the same database, with ownership linked back to the custom siteusers/ sites and permission checking related to the views. We keep the django user and sites framework as well, but use it/the admin for administration use only. This is the most complicated path, but I think the advantages make it worth it for a large number of sites. We can add sites using an admin interface, and use fewer resources since caching and workers are all shared. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
User/UserProfile Queryset problem
Hello Django Nerds! So I have a (somewhat) complicated lookup I'm trying to do; here's the gist of it: 1. I have a Store class, with a User ManyToManyField, Store.users 2. I have a user profile class associated with each user, UserProfile, accessible through the usual User.get_profile() 3. UserProfile has a status variable, UserProfile.status, which can be 'Active', 'Inactive', or 'Deleted' I'm trying to display a list of users for a particular store; currently I generate this list using the following line: userList = request.session['currentStore'].users.all() Works great; however, now I'd like to filter out all users with a status of 'Deleted'. Now, if status were a User attribute, I could just try this: userList = request.session['currentStore'].users.exclude(status=='Deleted') or something similar. THE PROBLEM: How do I generate this no-deleted-users list for the given store, using the ManyToManyField Store.users, but based on the store.users UserProfile.status? I know there's some kinky django black magic reverse-lookup way to do it in a single magnificent line...just haven't a clue what it might be. Ideas? First person with the right answer: thank you - please treat yourself to a donut... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Adding link to admin page
On 27/03/2012 10:16am, Larry Martell wrote: On Mon, Mar 26, 2012 at 4:37 PM, Mike Dewhirst wrote: On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: On Mar 25, 3:29 pm, Larry Martellwrote: I have a client that has an app built with django. On every page of their app is a link to their admin site. They tell me the admin site is generated entirely by django, and they've never customized it before. On the very first line of the admin page it says: Django administration Welcome, admin. Change password / Log out They want me to add a link to that line, to the left of "Django administration" that will take them back to the page they were on when they clicked on the link to get them to the admin site. So I have 2 issues here: 1) How do I override that line to add the link? It appears that page is generated by contrib/admin/templates/admin/base.html, and I tried to override it by following the directions athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., but whatever I do seems to have no effect. 2) How can I get the link of the page of the app they came from? It's not simply just going back one page, as they could have navigated all over the place of the admin site before clicking the "Back to app" link. Thanks! -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders Basically, django uses the first template it finds so if it finds the "real" one in site-packages first, it stops looking. Try reversing the sequence of loaders in your settings.py Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this: TEMPLATE_LOADERS = ( 'appmngr.load_app_template', 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', ) Where the first entry is a custom template loader that doesn't appear to know how to load something from my apps templates/admin dir. Are the other 2 entries 'standard' loaders that would look for my base_site.html (since I put full path to it in TEMPLATE_DIRS)? Here is mine ... 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ... it looks like your settings.py is using the template API load_template_source() for some reason. If you didn't do that yourself, I'd suggest you experiment by putting my two Loaders ahead of your three and see what happens. Good luck Mike -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Adding link to admin page
On Mon, Mar 26, 2012 at 7:25 PM, Mike Dewhirst wrote: > On 27/03/2012 10:16am, Larry Martell wrote: >> >> On Mon, Mar 26, 2012 at 4:37 PM, Mike Dewhirst >> wrote: >>> >>> On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: On Mar 25, 3:29 pm, Larry Martell wrote: > > I have a client that has an app built with django. On every page of > their app is a link to their admin site. They tell me the admin site > is generated entirely by django, and they've never customized it > before. On the very first line of the admin page it says: > > Django administration Welcome, admin. Change password / Log > out > > They want me to add a link to that line, to the left of "Django > administration" that will take them back to the page they were on when > they clicked on the link to get them to the admin site. > > So I have 2 issues here: > > 1) How do I override that line to add the link? It appears that page > is generated by contrib/admin/templates/admin/base.html, and I tried > to override it by following the directions > > athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., > but whatever I do seems to have no effect. > > 2) How can I get the link of the page of the app they came from? It's > not simply just going back one page, as they could have navigated all > over the place of the admin site before clicking the "Back to app" > link. > > Thanks! > -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? >>> >>> >>> Check >>> https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders >>> >>> Basically, django uses the first template it finds so if it finds the >>> "real" >>> one in site-packages first, it stops looking. Try reversing the sequence >>> of >>> loaders in your settings.py >> >> Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this: >> >> TEMPLATE_LOADERS = ( >> 'appmngr.load_app_template', >> 'django.template.loaders.filesystem.load_template_source', >> 'django.template.loaders.app_directories.load_template_source', >> ) >> >> Where the first entry is a custom template loader that doesn't appear >> to know how to load something from my apps templates/admin dir. Are >> the other 2 entries 'standard' loaders that would look for my >> base_site.html (since I put full path to it in TEMPLATE_DIRS)? >> > Here is mine ... > > 'django.template.loaders.filesystem.Loader', > 'django.template.loaders.app_directories.Loader', > > ... it looks like your settings.py is using the template API > load_template_source() for some reason. If you didn't do that yourself, I'd > suggest you experiment by putting my two Loaders ahead of your three and see > what happens. No, I didn't set any of this up. It's an existing app, and I'm new to both the job and to django. There's only one other developer working on the project, and he's part time and doesn't always respond to my questions. In any case, I tried that and it had no effect. Thanks for trying. -larry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Adding link to admin page
Larry Here is a working setup ... From settings.py # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if templates are not found here look in app_name/templates TEMPLATE_DIRS = ( os.path.join(SRC_ROOT, 'templates/').replace('\\','/'), ) # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( # filesystem ahead of app_directories looks in project before django 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.messages.context_processors.messages', ) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ... where SRC_ROOT is the directory containing settings.py. So my templates directory seems much the same as yours like this ... SRC_ROOT/templates/admin/base_site.html ... and inside base_site.html I have ... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% extends "admin/base.html" %} {# admin/base.html is in site-packages/django/contrib/admin/templates/admin #} {% load i18n %} {% block title %}{{ title }} | {% trans 'Ssds' %}{% endblock %} {% block extrastyle %}{% endblock %} {% block branding %} {% trans 'http://www.myproj.com.au";>MyProj Administration' %} {% endblock %} {% block nav-global %}{% endblock %} {% block extrahead %}{% endblock %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ... and you can see where I tested a link inside {% block branding %} and I can confirm it works. Hth Mike On 27/03/2012 12:46pm, Larry Martell wrote: On Mon, Mar 26, 2012 at 7:25 PM, Mike Dewhirst wrote: On 27/03/2012 10:16am, Larry Martell wrote: On Mon, Mar 26, 2012 at 4:37 PM, Mike Dewhirst wrote: On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: On Mar 25, 3:29 pm, Larry Martell wrote: I have a client that has an app built with django. On every page of their app is a link to their admin site. They tell me the admin site is generated entirely by django, and they've never customized it before. On the very first line of the admin page it says: Django administration Welcome, admin. Change password / Log out They want me to add a link to that line, to the left of "Django administration" that will take them back to the page they were on when they clicked on the link to get them to the admin site. So I have 2 issues here: 1) How do I override that line to add the link? It appears that page is generated by contrib/admin/templates/admin/base.html, and I tried to override it by following the directions athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., but whatever I do seems to have no effect. 2) How can I get the link of the page of the app they came from? It's not simply just going back one page, as they could have navigated all over the place of the admin site before clicking the "Back to app" link. Thanks! -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders Basically, django uses the first template it finds so if it finds the "real" one in site-packages first, it stops looking. Try reversing the sequence of loaders in your settings.py Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this: TEMPLATE_LOADERS = ( 'appmngr.load_app_template', 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', ) Where the first entry is a custom template loader that doesn't appear to know how to load something from my apps templates/admin dir. Are the other 2 entries 'standard' loaders that would look for my base_site.html (since I put full path to it in TEMPLATE_DIRS)? Here is mine ... 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ... it looks like your settings.py is using the template API load_template_source() for some reason. If you didn't do that yourself, I'd suggest you experiment by putting my two Loaders ahead of your three and see what happens. No, I didn't set any of this up. It's an existing app, and I'm new to both the job and to django. There's only one other developer working on the project, and he's part time and doesn't always respond to my questions. In any case, I tried that and it had no effec
Re: Adding link to admin page
I should have mentioned that {% extends "admin/base.html" %} is actually extending the django admin/base.html in site-packages because there is no such file in my SRC_ROOT/templates/admin directory. Mike On 27/03/2012 2:19pm, Mike Dewhirst wrote: Larry Here is a working setup ... From settings.py # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if templates are not found here look in app_name/templates TEMPLATE_DIRS = ( os.path.join(SRC_ROOT, 'templates/').replace('\\','/'), ) # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( # filesystem ahead of app_directories looks in project before django 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.messages.context_processors.messages', ) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ... where SRC_ROOT is the directory containing settings.py. So my templates directory seems much the same as yours like this ... SRC_ROOT/templates/admin/base_site.html ... and inside base_site.html I have ... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% extends "admin/base.html" %} {# admin/base.html is in site-packages/django/contrib/admin/templates/admin #} {% load i18n %} {% block title %}{{ title }} | {% trans 'Ssds' %}{% endblock %} {% block extrastyle %}{% endblock %} {% block branding %} {% trans 'http://www.myproj.com.au";>MyProj Administration' %} {% endblock %} {% block nav-global %}{% endblock %} {% block extrahead %}{% endblock %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ... and you can see where I tested a link inside {% block branding %} and I can confirm it works. Hth Mike On 27/03/2012 12:46pm, Larry Martell wrote: On Mon, Mar 26, 2012 at 7:25 PM, Mike Dewhirst wrote: On 27/03/2012 10:16am, Larry Martell wrote: On Mon, Mar 26, 2012 at 4:37 PM, Mike Dewhirst wrote: On 27/03/2012 9:16am, larry.mart...@gmail.com wrote: On Mar 25, 3:29 pm, Larry Martell wrote: I have a client that has an app built with django. On every page of their app is a link to their admin site. They tell me the admin site is generated entirely by django, and they've never customized it before. On the very first line of the admin page it says: Django administration Welcome, admin. Change password / Log out They want me to add a link to that line, to the left of "Django administration" that will take them back to the page they were on when they clicked on the link to get them to the admin site. So I have 2 issues here: 1) How do I override that line to add the link? It appears that page is generated by contrib/admin/templates/admin/base.html, and I tried to override it by following the directions athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a..., but whatever I do seems to have no effect. 2) How can I get the link of the page of the app they came from? It's not simply just going back one page, as they could have navigated all over the place of the admin site before clicking the "Back to app" link. Thanks! -larry Is there anyone that can provide some assistance with overriding base_site.html? I copied django/contrib/admin/templates/admin/ base_site.html to my projects's templates/admin dir, but changes to it are not getting picked up. I also tried adding that to TEMPLATE_DIRS (there was nothing in it before). In urlpatterns I have: (r'^admin/', include(admin.site.urls)) - does that need to change? Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders Basically, django uses the first template it finds so if it finds the "real" one in site-packages first, it stops looking. Try reversing the sequence of loaders in your settings.py Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this: TEMPLATE_LOADERS = ( 'appmngr.load_app_template', 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', ) Where the first entry is a custom template loader that doesn't appear to know how to load something from my apps templates/admin dir. Are the other 2 entries 'standard' loaders that would look for my base_site.html (since I put full path to it in TEMPLATE_DIRS)? Here is mine ... 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ... it looks like your settings.py is using the template API load_template_source() for some reason. If you didn't do that yourself, I'd suggest you experiment by putting my two Loaders ahead of your three and see what happens. No, I didn't set any of this up. It's an existing app, and I'm new to both the job and to django. T
Adding 'extra_context' variable to Class-based views
Now that Django 1.4 is among us, function-based generic views are really being phased out, and for those who use 'extra_context', but dislike the method used implement it: class MyListView(ListView): def get_context_data(self, **kwargs): context = super(MyListView, self).get_context_data(**kwargs) context.update({ 'foo': 42, 'bar': 37 }) return context Have a look at my tutorial on how to implement something similar to Django 1.2 and below to ease migration. This is mainly useful if you use one shot 'extra_contexts' in a generic view, this tutorial will allow this in your urls.py: ContextListView.as_view(queryset=Book.objects.filter(public=True),extra_context={'form':NewBookForm()}) http://www.pythondiary.com/tutorials/django-13-generic-views-and-extra_context.html Hope it helps people on the migration path to Django 1.4. I am currently in the progress of migration, and will be writing some tutorials and blog posts about my experiences. Kevin. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/PtkpfwVHSiEJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: User/UserProfile Queryset problem
On Tuesday, 27 March 2012 02:15:04 UTC+1, bcrem wrote: > > Hello Django Nerds! > > So I have a (somewhat) complicated lookup I'm trying to do; here's the > gist of it: > > 1. I have a Store class, with a User ManyToManyField, Store.users > 2. I have a user profile class associated with each user, > UserProfile, accessible through the usual User.get_profile() > 3. UserProfile has a status variable, UserProfile.status, which can > be 'Active', 'Inactive', or 'Deleted' > > I'm trying to display a list of users for a particular store; > currently I generate this list using the following line: > >userList = request.session['currentStore'].users.all() > > Works great; however, now I'd like to filter out all users with a > status of 'Deleted'. Now, if status were a User attribute, I could > just try this: > >userList = > request.session['currentStore'].users.exclude(status=='Deleted') > > or something similar. > > THE PROBLEM: How do I generate this no-deleted-users list for the > given store, using the ManyToManyField Store.users, but based on the > store.users UserProfile.status? I know there's some kinky django > black magic reverse-lookup way to do it in a single magnificent > line...just haven't a clue what it might be. Ideas? > > First person with the right answer: thank you - please treat yourself > to a donut... The session seems to be a red herring here. You're just doing a filter across a related field, which is done with the normal double-underscore syntax: current_store.users.exclude(userprofile__status='Deleted') -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sVcHJjNplGoJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Simple question on queryset.
Hello, How do i transform this SQL query into a queryset? select membership_type from memberships where id ='4' i tried the following: queryset = Memberships.objects.get(id__exact=4) however django is throwing me an error with the following: Memberships has no attribute all. I know this is a trivial question but i've been through the tutorials https://docs.djangoproject.com/en/dev/topics/db/queries/ and i don't unds where this error is coming from. Do appreciate any help rendered. Thank you. Best Regards, Stanwin Siow -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.