Re: logging django errors also on the server
On 09/05/2011 03:05 AM, Reinout van Rees wrote: > On 05-09-11 02:25, Gelonida N wrote: >> I see my own log traces. >> In many situations I do see error messages in the log output. > > An important thing that's not mentioned too clearly in Django 1.3's > logging docs: *add a root logger*. So a logger with an empty string as a > name. That one catches all messages, including the ones to the > django.something.error logger. > True, That's not added in the doc and could be added for clarity. I had already a root logger added though. So my problem must be somewhere else. Will keep you informed when I manage to replicate the issue or when I understand what went wrong. -- 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.
time part of datetime not saved
I have a model start = models.DateTimeField() In my view I create a datetime: x = datetime.datetime(*(time.strptime(str(component.get('dtstamp')),'%Y %m%dT%H%M%SZ')[0:6])) . This return a valid datetime: >>> x datetime.datetime(2011, 9, 4, 8, 45, 32) The problem is that only the date part is saved in the database. The time is saved as zero's: >>> db.created datetime.datetime(2011, 9, 4, 0, 0) Do i need to convert the date before saving it into the database? -- 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: time part of datetime not saved
*dump your code ?! * *BTW, * *You can set auto_now_add = true in the model, which will assign the current datetime, while saving without any code at all. * On Mon, Sep 5, 2011 at 11:54 AM, het.oosten wrote: > I have a model start = models.DateTimeField() > > In my view I create a datetime: > x = datetime.datetime(*(time.strptime(str(component.get('dtstamp')),'%Y > %m%dT%H%M%SZ')[0:6])) . > > This return a valid datetime: > >>> x > datetime.datetime(2011, 9, 4, 8, 45, 32) > > The problem is that only the date part is saved in the database. The > time is saved as zero's: > >>> db.created > datetime.datetime(2011, 9, 4, 0, 0) > > Do i need to convert the date before saving it into the database? > > -- > 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. > > -- Thanks and Regards, *Praveen Krishna R* -- 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: Class-based FormView Contact Form
Anyone? I really want to use class-based views, but it is hard with so much missing in terms of examples/tutorials. thx. -- 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/-/E5tqbVq8HNsJ. 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: time part of datetime not saved
Here is a code dump (still work in progress :-) ): http://pastebin.com/szQKRw7d -- 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: time part of datetime not saved
Oh btw, it is all about importing a facebook eventcalendar (in icalendar format) into a database. -- 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: time part of datetime not saved
Can you tell us what is the "[0:6]" supposed to be doing in your time conversion funcions? -- 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: time part of datetime not saved
It is a python 2.4 workaround for using strptime. Without the '[0:6]' I get this error: TypeError: function takes at most 8 arguments (9 given) -- 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: time part of datetime not saved
Just call it a hunch, but can you try [0:8] please..? Sent from my BlackBerry® from Vodafone -Original Message- From: "het.oosten" Sender: django-users@googlegroups.com Date: Mon, 5 Sep 2011 04:30:44 To: Django users Reply-To: django-users@googlegroups.com Subject: Re: time part of datetime not saved It is a python 2.4 workaround for using strptime. Without the '[0:6]' I get this error: TypeError: function takes at most 8 arguments (9 given) -- 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.
Re: time part of datetime not saved
On 5 sep, 13:40, bik...@gmail.com wrote: > Just call it a hunch, but can you try [0:8] please..? I get this error in that case TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'int' I think that the strptime works correctly, because the returned datetime is: datetime.datetime(2011, 9, 4, 8, 45, 32) (see topicstart) -- 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: time part of datetime not saved
On 2011-09-05, at 13:13 , Jirka Vejrazka wrote: > Can you tell us what is the "[0:6]" supposed to be doing in your time > conversion funcions? strptime returns a struct_time[0] which is a 9-tuple. The datetime constructor takes up to 8 arguments, but the last 2 are microseconds and a tzinfo object, whereas timetuple's indexes 6 to 8 hold respectively the weekday, the yearday and a daylight saving flag (for mktime). So strptime and datetime are compatible on their first 6 values (return for strptime, input for datetime), hence the slicing of strptime's result to get only the first 6 values. [0] http://docs.python.org/library/time.html#time.struct_time -- 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: time part of datetime not saved
OK - I can't see anything wrong with your code that'd jump at me. Can you check your database table format? Maybe you've declared your model fields as models.DateField first and then changed to DateTimeField without changing the underlying table? Just a guess :) Jirka -- 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: time part of datetime not saved
On 2011-09-05, at 14:08 , Jirka Vejrazka wrote: > OK - I can't see anything wrong with your code that'd jump at me. Can > you check your database table format? Maybe you've declared your model > fields as models.DateField first and then changed to DateTimeField > without changing the underlying table? Just a guess :) > > Jirka Yeah that's what I'd think of as well, the values are definitely correct before entering the db. -- 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: time part of datetime not saved
I did change the model from DateField to DateTimeField, removed the table, synced the database and restarted the wsgi instance. As I found out I should have restarted the wsgi server right after deleting the table from the database. The second time I did remove, recreate and restart in the same sequence, and it still didn't work. After the third time everything works great :-) You were absolutely right there. Thanks a lot for your help! -- 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: logging django errors also on the server
Take a look at Sentry: http://readthedocs.org/docs/sentry/ It works pretty well, uses polling to update the log view, can track multiple sites with separate Sentry Server, etc. Good luck, Uros On Sep 5, 12:58 am, Gelonida N wrote: > Hi, > > Im am debugging a django application. > > If I set DEBUG=True > then I can see error messages on the browser. > > Is there any way to see the same error messages in the server log file? > Occasionally (especially for rpc client or Ajax requests I would prefer > looking at the log file instead of looking at the browser error messages) > > Thanks for any suggestions. -- 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: Beginner's unit test question
On Sep 5, 5:18 am, Rodney Topor wrote: > I'm trying to use unit tests for the first time. > > In app/tests.py I have: > > import unittest > from django.test.client import Client > > class IndexTest(unittest.TestCase): > def test_index(self): > client = Client() > response = client.get('/index/') > self.assertEqual(response.status_code, 200) > > In the enclosing project directory, I write > > manage.py test app.IndexTest > > and get the error > > "Test label 'messages.IndexTest' does not refer to a test" You were talking about an app named "app", not "messages"... Please try to be as exact as possible. > I also tried "from django.utils import unittest" in tests.py but that > made no difference. > > The command > > manage.py test app > > runs without error but ignores my test. > I thought I was following the instructions in the documentation, but > apparently not. What am I missing? Do I have to add some test app to > INSTALLED_APPS in settings.py? Nope. As long as your app is mentionned in INSTALLED_APPS (and you'd have a different exception if it wasn't the case), this should work. -- 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: foregin keys
On Sep 4, 7:20 pm, Kevin Anthony wrote: > hi, how do i join two models on something OTHER then the primary key? You didn't search for long, did you ? https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.ForeignKey.to_field Please do the minimal required homework before asking for help next time... -- 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: sitemap
> Exception Value: Reverse for 'entry' with arguments '('my 1st post',)'look at > urls.py > Date: Sun, 4 Sep 2011 22:25:50 -0700 > Subject: sitemap > From: veva...@yandex.ru > To: django-users@googlegroups.com > > Would You please help me to find a mistake? > --- blog.model.py: > from django.db import models > class Entry(models.Model): > title = models.CharField(max_length=150) > body = models.TextField() > is_draft = models.BooleanField() > pub_date = models.DateField() > > def __unicode__(self): > return self.title > > @models.permalink > def get_absolute_url(self): > return('entry', [str(self.title)]) > > --- blog.sitemap.py: > from django.contrib.sitemaps import Sitemap > > class BlogSitemap(Sitemap): > changefreq = "never" > priority = 0.5 > def items(self): > return Entry.objects.filter(is_draft==1) > def lastmod(self, obj): > return obj.pub_date > > --- urls.py: > from django.conf.urls.defaults import * > from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap > from testsitemap.blog.models import Entry > from django.contrib import admin > admin.autodiscover() > > info_dict = { > 'queryset': Entry.objects.all(), > 'date_field': 'pub_date', > } > > sitemaps = { > 'flatpages': FlatPageSitemap, > 'blog': GenericSitemap(info_dict, priority=0.6), > } > > urlpatterns = patterns('', > url(r'^entry/(\w+)/$', 'archive', > name='entry > ), > url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', > {'sitemaps': sitemaps}), > ) > > --- blog.views.py: > from django.shortcuts import render_to_response > from testsitemap.blog.models import Entry > > def archive(request): > posts = Entry.objects.all() > return render_to_response('archive.html', {'posts': posts }) > > --- error message: > Request Method: GET > Request URL: http://localhost:8000/sitemap.xml > Django Version: 1.3 > Exception Type: NoReverseMatch > Exception Value: Reverse for 'entry' with arguments '('my 1st post',)' > and keyword arguments '{}' not found. > Exception Location: C:\Python26\lib\site-packages\django\core > \urlresolvers.py in reverse, line 337 > > Thank You very much! > > -- > 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.
Re: Class-based FormView Contact Form
On Mon, Sep 5, 2011 at 6:17 PM, Paul Walsh wrote: > Anyone? > I really want to use class-based views, but it is hard with so much missing > in terms of examples/tutorials. Hi Paul, First off, apologies for the current state of the Class-based views documentation. It's one of the known weak points in the documentation at the moment, and something that I'd really like to rectify. Secondly, to address your actual question -- it depends on exactly what you want to do. If you're just looking to pass in an extra argument to the Form instance when it is constructed in an UpdateView or CreateView, then you should be looking to the extension points in the FormMixin class - in particular, get_form() (which constructs the form instance), and/or get_form_kwargs(), which returns the arguments that will be passed to construct the form. So, if you just want to add a "recipient=foo" argument to the form constructor, override get_form_kwargs(), and add the extra argument to the dictionary constructed by the parent, and return the result: class MyView(UpdateView) ... def get_form_kwargs() kwargs = super(MyFormClass, self).get_form_kwargs() kwargs.update({'recipient': ... }) return kwargs An alternative is to take a different look at the way you're using the form. If the recipient isn't actually necessary for form processing itself (i.e., it's just there as a required default value for a model instance), then don't pass it to the form at all. Instead, set the value for recipient on the instance, and just don't save that change. In a normal function based view, this is the equivalent of something like: instance = Thing.objects.get(...) instance.recipient = 'f...@example.com' if request.method == 'POST': form = MyThingForm(instance=instance, data=request.POST) This means that the instance used by the form is saveable -- because it has a valid value for recipient -- but it doesn't require any custom arguments to the instance itself. To do this in a class-based view, look to the get_object() method on the SingleObjectMixin. This is the method that is used to retrieve the instance that will be manipulated; if you override get_object() and add the extra recipient argument, then whenever a view needs an object instance, it will be given one with a pre-set recipient value. As a last resort -- I would actually suggest digging into the CBV source code a bit. It may seem daunting to do this, but the CBV code is quite well documented code, and although there are a lot of methods, most of them are fairly simple internally. I know this isn't a good substitute for having adequate documentation, but it may be better than nothing. Hope that helps! Yours, Russ Magee %-) -- 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.
Use primary key in filenames on FileFields
Hello, I have a model that includes a FileField. When the user uploads a file via the admin interface, I want the file to be saved as 'upload_to/ primary_key/original_filename'. Since the object will not be saved in the database when the user uploads the file, it will not have a primary key at that point. This is my workaround: class Decision(m.Model): ... decision = m.FileField(upload_to='base_dir/') ... def save(self, *args, **kwargs): """ custom save to use pk on filename """ #save once to get a pk super(Decision, self).save(*args, **kwargs) #get info about the file uploaded = self.decision old_path = self.decision.name basedir, filename = os.path.split(old_path) new_path = os.path.join(basedir, str(self.pk), filename) #create the new file, delete the one django created uploaded.storage.save(new_path, uploaded) uploaded.storage.delete(old_path) #assign new path and save again self.decision = new_path super(Decision, self).save(*args, **kwargs) This works, but seems to be a bit on the hacky side. Basically, I'm letting FileField upload the file to the 'upload_to' path and then move it to its correct path when the object has a primary key. I was wondering if there is a better way to do this. Are there any cases where my code wouldn't work? 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: Use primary key in filenames on FileFields
I forgot to mention that i have imported models like this: import django.db.models as m This should explain the first two lines. On Mon, Sep 5, 2011 at 12:28 PM, Stratos Moros wrote: > Hello, > > I have a model that includes a FileField. When the user uploads a file > via the admin interface, I want the file to be saved as 'upload_to/ > primary_key/original_filename'. Since the object will not be saved in > the database when the user uploads the file, it will not have a > primary key at that point. This is my workaround: > > > class Decision(m.Model): > ... > decision = m.FileField(upload_to='base_dir/') > ... > > def save(self, *args, **kwargs): > """ custom save to use pk on filename """ > #save once to get a pk > super(Decision, self).save(*args, **kwargs) > > #get info about the file > uploaded = self.decision > old_path = self.decision.name > basedir, filename = os.path.split(old_path) > new_path = os.path.join(basedir, str(self.pk), filename) > > #create the new file, delete the one django created > uploaded.storage.save(new_path, uploaded) > uploaded.storage.delete(old_path) > > #assign new path and save again > self.decision = new_path > super(Decision, self).save(*args, **kwargs) > > > This works, but seems to be a bit on the hacky side. Basically, I'm > letting FileField upload the file to the 'upload_to' path and then > move it to its correct path when the object has a primary key. > > I was wondering if there is a better way to do this. Are there any > cases where my code wouldn't work? > > 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.
DecimalField values changing on save()
Hi all I know this is a bit of a corner case, but I was slightly surprised by the behaviour of DecimalField with the value -0.0. Given the model: class Word(models.Model): word = models.CharField(max_length=50, unique=True) number = models.DecimalField(max_digits=8, decimal_places=5) def __unicode__(self): return self.word I then get the following behaviour: > python2.7 manage.py shell In [1]: from vortaro.models import Word In [2]: from decimal import Decimal In [3]: word = Word(word='foo', number=Decimal('-0.0')) In [4]: word.save() In [6]: word_from_db = Word.objects.get() In [7]: word_from_db.number Out[7]: Decimal('0') In [8]: word.number Out[8]: Decimal('-0.0') Is it supposed to behave like this? Cheers Wilfred -- 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: Use primary key in filenames on FileFields
try this def get_file_path(instance, filename): path = 'your upload directory' extension = filename.split('.')[-1].lower() new_file_name = self.id return '%(path)s/%(filename)s.%(extension)s' % { 'path': path, 'filename': new_file_name', 'extension': extension } class Decision(m.Model): ... decision = m.FileField(upload_to=get_file_path) On Sep 5, 11:01 am, Stratos Moros wrote: > I forgot to mention that i have imported models like this: > > import django.db.models as m > > This should explain the first two lines. > > > > > > > > On Mon, Sep 5, 2011 at 12:28 PM, Stratos Moros wrote: > > Hello, > > > I have a model that includes a FileField. When the user uploads a file > > via the admin interface, I want the file to be saved as 'upload_to/ > > primary_key/original_filename'. Since the object will not be saved in > > the database when the user uploads the file, it will not have a > > primary key at that point. This is my workaround: > > > class Decision(m.Model): > > ... > > decision = m.FileField(upload_to='base_dir/') > > ... > > > def save(self, *args, **kwargs): > > """ custom save to use pk on filename """ > > #save once to get a pk > > super(Decision, self).save(*args, **kwargs) > > > #get info about the file > > uploaded = self.decision > > old_path = self.decision.name > > basedir, filename = os.path.split(old_path) > > new_path = os.path.join(basedir, str(self.pk), filename) > > > #create the new file, delete the one django created > > uploaded.storage.save(new_path, uploaded) > > uploaded.storage.delete(old_path) > > > #assign new path and save again > > self.decision = new_path > > super(Decision, self).save(*args, **kwargs) > > > This works, but seems to be a bit on the hacky side. Basically, I'm > > letting FileField upload the file to the 'upload_to' path and then > > move it to its correct path when the object has a primary key. > > > I was wondering if there is a better way to do this. Are there any > > cases where my code wouldn't work? > > > 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.
Minimal change broken my csrf validation.
Can you please take a look at here: http://stackoverflow.com/q/7312029/886669 -- http://yasar.serveblog.net/ -- 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.
Authorization workflow model
Hello, Does anyone knows some solution (reusable app, snippet or any idea) to model an authorization workflow of data? That is... supose that a user have restricted some model field, ie, cannot edit directly this field. And now supose that he could request to change that field, seeing the real content and editing it, and then "save" model. Saving model, doesn't commit the transaction, until another user (an administrator) authorize the change (the actual commit). Any idea? A trivial idea is to have another request model replicating the structure (or only the restricted fields) of the original one. So, the user who need to change the restricted fields completes this new model. For example: class Foo(model.Models): name = models.CharField() class FooRequest(model.Models): name = models.CharField() Then we need an action to copy and replace data to Foo from FooRequest. The problem with this solution, is that i need it for a lot of models, not just one. Thanks for your time, Regards, Mario. -- 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: Authorization workflow model
You could use a model with three fields: A generic foreign key to the instance to be modified. A char field containing the fieldname on that instance. The new value. Of course you'd need another field to store the user (assuming the person making the authorization will base their decision on who's making the request). Also, it'll get a little more complicated if you want to store values for different field types (boolean vs. string, for example), and maybe a boolean or a datetime field to indicate when the request was accepted/denied. Then you can store a field indicating whether it was approved or declined... So, the basics are at the top. Then you'll have to implement as much of the rest as you'll need. -- 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.
forms.ChoiceField/forms.ModelChoiceField Needs a Lot of Love
I don't know if anyone has said this outright, but I think that ChoiceField and ModelChoiceField are just broken. It seems that every time I want to do something with them I'm having to write a custom init function get what I want done. As a community I think we should be able to improve the "genericness" of them in such a way that would allow smart filtering of model lists, default settings, and a few other features that as an object they are wonting for. I know that this remark is far too generic and requires a great deal more "fleshing out" but I wanted to throw that out there as I'm banging my head -- once again -- on the desk trying to get django forms to spit out a choice field that does what I want it to do and wished to share my frustration. -- 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.
admin site not showing up?
I'm dutifully following the instructions at the django tutorial (https://docs.djangoproject.com/en/1.3/intro/tutorial02/). I have amended admin.py and urls.py as indicated and restarted the server; however, the admin website does NOT provide any interface to the polls app. Instead, it tells me: "Site administration You don't have permission to edit anything." What should I check/verify to make sure everything is configured correctly? Thanks, --Steve -- 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: Beginner's unit test question
I'm sorry for my inconsistency. I tried to "simplify", but made a mistake. In fact, I used the app "messages" throughout, in my code and in the test command. The project containing the app works fine. In particular, the app "messages" is included in INSTALLED_APPS. So, if the test "should work" as I've written it, can anyone suggest what might be wrong? Django configuration error? Settings error? Permissions error? Something else? On Sep 5, 11:48 pm, bruno desthuilliers wrote: > On Sep 5, 5:18 am, Rodney Topor wrote: > > > > > > > I'm trying to use unit tests for the first time. > > > In app/tests.py I have: > > > import unittest > > from django.test.client import Client > > > class IndexTest(unittest.TestCase): > > def test_index(self): > > client = Client() > > response = client.get('/index/') > > self.assertEqual(response.status_code, 200) > > > In the enclosing project directory, I write > > > manage.py test app.IndexTest > > > and get the error > > > "Test label 'messages.IndexTest' does not refer to a test" > > You were talking about an app named "app", not "messages"... Please > try to be as exact as possible. > > > I also tried "from django.utils import unittest" in tests.py but that > > made no difference. > > > The command > > > manage.py test app > > > runs without error but ignores my test. > > I thought I was following the instructions in the documentation, but > > apparently not. What am I missing? Do I have to add some test app to > > INSTALLED_APPS in settings.py? > > Nope. As long as your app is mentionned in INSTALLED_APPS (and you'd > have a different exception if it wasn't the case), this should work. -- 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: admin site not showing up?
Figured it out: gotta run autodiscover(). --Steve -- 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: Beginner's unit test question
Never mind. I've found the answer. The problem was that my app name "messages" somehow clashed with the app "django.contrib.messages" which was earlier in my INSTALLED_APPS. This didn't prevent my project from working, but did confuse the test framework, which looked in "django.contrib.messages" before "myproject.messages" for test cases. When I renamed my app, the testing worked fine. So Bruno's advice was correct: give the exact details, don't simplify, that just discards important information. OK, now to start writing serious unit tests... On Sep 5, 11:48 pm, bruno desthuilliers wrote: > On Sep 5, 5:18 am, Rodney Topor wrote: > > > > > > > I'm trying to use unit tests for the first time. > > > In app/tests.py I have: > > > import unittest > > from django.test.client import Client > > > class IndexTest(unittest.TestCase): > > def test_index(self): > > client = Client() > > response = client.get('/index/') > > self.assertEqual(response.status_code, 200) > > > In the enclosing project directory, I write > > > manage.py test app.IndexTest > > > and get the error > > > "Test label 'messages.IndexTest' does not refer to a test" > > You were talking about an app named "app", not "messages"... Please > try to be as exact as possible. > > > I also tried "from django.utils import unittest" in tests.py but that > > made no difference. > > > The command > > > manage.py test app > > > runs without error but ignores my test. > > I thought I was following the instructions in the documentation, but > > apparently not. What am I missing? Do I have to add some test app to > > INSTALLED_APPS in settings.py? > > Nope. As long as your app is mentionned in INSTALLED_APPS (and you'd > have a different exception if it wasn't the case), this should work. -- 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.
Admin TabularInline Edit Parent Record?
I use TabularInlines for Many-to-Many join tables, with the foreign keys appearing in select lists. The Admin interface automatically provides the stellar "Add-Another" icon (a plus sign) with the select list, to add a new parent record on the fly. It would be extremely useful to also have an edit icon (often a pencil) that would edit the related parent record. Any easy way to to do that? Thanks for any help or ideas. Lee -- 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: Authorization workflow model
On 6/09/2011 5:46am, Mario8k wrote: Hello, Does anyone knows some solution (reusable app, snippet or any idea) to model an authorization workflow of data? That is... supose that a user have restricted some model field, ie, cannot edit directly this field. And now supose that he could request to change that field, seeing the real content and editing it, and then "save" model. Saving model, doesn't commit the transaction, until another user (an administrator) authorize the change (the actual commit). Any idea? I would consider keeping all the edits in the same record. Then you could have 'approved' and 'edited' as two versions of the field. For example, the lower-privileged user edits a copy of 'approved' in 'edited' and save() just saves it. When the admin eventually approves it, the 'edited' field gets copied to the real field. mike A trivial idea is to have another request model replicating the structure (or only the restricted fields) of the original one. So, the user who need to change the restricted fields completes this new model. For example: class Foo(model.Models): name = models.CharField() class FooRequest(model.Models): name = models.CharField() Then we need an action to copy and replace data to Foo from FooRequest. The problem with this solution, is that i need it for a lot of models, not just one. Thanks for your time, Regards, Mario. -- 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 use ModelForm for both new or existing data
Hi, I'm having trouble figuring out the best way to use ModelForm in the following situation. I have these post variables coming into the view course_id course_department course_number And course_id may or may not be an empty string. If I do course_form = CourseForm(request.POST) Then the problem is that if the course already exists, the CourseForm's says it's not valid. If I do course = Course.objects.get(pk=request.POST.get(course_id, '') course_form = CourseForm(request.POST, instance=course) The problem is that course_id might be an empty string (a bug which I can't reproduce and don't understand but does happen and I have to deal with it) So if I do course = Course.objects.get_or_create(department = request.POST.get('course_department', ''), number = request.POST.get('course_number', '')) course_form = CourseForm(request.POST, instance=course) Then the CourseForm is redundant since I have to do all my own validation to use course_department and course_number in the first place. That puts my brain in a recursive loop and I'm having trouble figuring out the best thing to do. Any suggestions would help. You can see the actual codebase here: http://code.google.com/p/cube-bookstore/source/browse/trunk/cube/books/views/metabooks.py#109 -- 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 use ModelForm for both new or existing data
How about checking for the existence of course_id in the view? Then if it's blank you just send request.POST and if not you grab the instance in the view and pass it as the instance kwarg. Alternately you could do the same in the __init__ of the modelform, before you call the super __init__. It depends on which one will be easier to understand and maintain for your app. -- 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.