Re: Trying to understand Django and Python from a C++ perspective

2009-06-30 Thread Lachlan Musicman

On Wed, Jul 1, 2009 at 06:02, zweb wrote:
>
> What book or resource would you recommend to learn advanced Python?
> (other than python docs)

"How to think like a computer scientist":
http://www.greenteapress.com/thinkpython/

-- 
"I'm in IT and we generally know how to use the interwebs like superheros." - AF

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Why doesn't my isinstance() work?

2010-04-20 Thread Lachlan Musicman
Hola,

I'm having trouble getting a subclass to trigger an isinstance(). Code below:

model.py excerpt:

from django.db import models
from django.forms import ModelForm

class Author(models.Model):
  first = models.CharField(u'First Name', max_length=20)
  other = models.CharField(u'Other Names', max_length=20, blank=True)
  last = models.CharField(u'Last Name', max_length=20)

  class Meta:
ordering = ['last']

  def __unicode__(self):
return u'%s %s' % (self.first, self.last)

  def get_absolute_url(self):
return "/author/%i" % self.str()

class Translator(Author):
  language = models.CharField(max_length=10, choices=LANGUAGES)

  class Meta:
verbose_name = 'Translator'
verbose_name_plural = 'Translators'


views.py excerpt:

from django.shortcuts import render_to_response, get_object_or_404
from booktrans.books.models import *
from django.template import RequestContext
from django.http import HttpResponseRedirect

def index(request):
  all_authors = Author.objects.all()
  all_origAuthors = []
  all_translators = []
  for author in all_authors:
if isinstance(author, Translator):
   all_translators.append(author)
else:
  all_origAuthors.append(author)
  return render_to_response('books/index.html',locals())



And from the shell:

>>> from booktrans.books.models import *
>>> t = Translator.objects.all()
>>> t
[, ]
>>> t = Translator.objects.get(pk=2)
>>> t

>>> isinstance(t, Translator)
True
>>> a = Author.objects.get(pk=1)
>>> isinstance(a, Translator)
False



Any tips?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Why doesn't my isinstance() work?

2010-04-21 Thread Lachlan Musicman
On Wed, Apr 21, 2010 at 19:33, Daniel Roseman  wrote:
>>
>> Any tips?
>
> This is the expected behaviour. You've asked for an Author object, so
> that's what you've got. There's no way to tell from the Author model
> that this particular instance of it is also an instance of Translator.

I presume this will make you all wince, but while appreciating the
discussion I've caused I've solved it thusly:

views.py
def index(request):
 all_authors = Author.objects.all()
 all_origAuthors = []
 all_translators = Translators.objects.all()
 for author in all_authors:
   if author in all_translators:
 pass
   else:
 all_origAuthors.append(author)
 return render_to_response('books/index.html',locals())


That nested loop is pretty inefficient, but it's a low visit site and
it shouldn't matter too much.

The other piece of advice I got was that I should have created a
second subclass:

class Author(Models.model) - this class _could_ be abstracted in this change.

class Writer(Author) - the Original Author
class Translator(Author)

Whether Author is abstract or not, we don't create any Author objects
directly, only Writer and Translator. Then it's easier :)

cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



loaddata and m2m backend tables...

2010-04-25 Thread Lachlan Musicman
Hi,

I used loaddata to insert some data into my app - now all my model
related tables are correctly populated.

How do I fill in the many to many tables, since there isn’t a model
that directly represents those tables?

I found this: http://www.b-list.org/weblog/2007/nov/21/install-time/
but it suggested "use loaddata", which hasn't worked for me...

ie:

class Book(models.Model):
  title = models.CharField(max_length=100)
  publisher = models.CharField(max_length=40)
  date = models.IntegerField()
  place = models.CharField(max_length=20)
  pages = models.IntegerField(blank=True, null=True)
  authors = models.ManyToManyField(Author)

class Writer(models.Model):
  first = models.CharField(u'First Name', max_length=30)
  other = models.CharField(u'Other Names', max_length=30, blank=True)
  last = models.CharField(u'Last Name', max_length=30)
  dob = models.DateField(u'Date of Birth', blank=True, null=True)

  class Meta:
abstract = True

class Author(Writer):
  language = models.CharField(max_length=20, choices=LANGUAGES, blank=True)


books_book and books_author are fine...but how do I populate books_book_authors?

cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: loaddata and m2m backend tables...

2010-04-25 Thread Lachlan Musicman
On Mon, Apr 26, 2010 at 15:06, Lachlan Musicman  wrote:
>
> How do I fill in the many to many tables, since there isn’t a model
> that directly represents those tables?

Ah, just import it straight into database, works a treat. I used
phpmyadmin and my csv dump. No need for loaddata at all.

Cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: translation for variables

2010-07-09 Thread Lachlan Musicman
On Fri, Jul 9, 2010 at 07:05, Börni  wrote:
> Hello together,
> i'm using the trans tpl tag for translation a value from database. If
> i'm adding this value to my django.po file and run makemessages
> afterwards, my changes got lost.

Are you manually adding the field to your po file?

Are you running "django-admin.py compilemessages" to create the
relevant django.mo file after the event?

Are there other strings in the same template that _are_ being translated?

Which version of django are you using?

Which language are you translating too?

cheers
L.



>
> I wonder how it's possible to handle such situations?
>
> Thank you very much,
> Börni
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: translation for variables

2010-07-10 Thread Lachlan Musicman
On Sat, Jul 10, 2010 at 05:26, Börni  wrote:
>> > Hello together,
>>
>> Are you running "django-admin.py compilemessages" to create the
>> relevant django.mo file after the event?
>
> Yes, i've tried it with the existing django.po file. And my other try
> was to create an additional file called database.po
>
> makemessages  removes my manualy added entries from django.po

Well, actually it doesn't remove them so much as not recognise them,
and therefore not including them at merge time. Makemessages is a
wrapper around gnu's gettext which does all the creation an d merging
automagically.

Hence, you can't just "add" a msgid to a po file - if the actual
string is not in the file, or not marked to be translated, it wont
appear in the po file.

> compilemessages creates mo files from my database.po and django.mo
> file, but django seems to ignore translations from any other files
> than django.mo?

Yes, that is expected behavior. All translations are expected to go
into a django.po file. All of my apps have a locale folder that
contains the relevant lang po|mo files...This means you will have a
_lot_ of django.po files scattered throughout you various apps, but
that's how it works. Since most apps use some form of version control
makes this easy enough, given the generally tiny file size of po|mo
files.

> Have a nice day and thank you very much for help,

No hassles mate. If my explanations don't make sense, let me know.

cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Help with localization

2010-07-25 Thread Lachlan Musicman
I have L10n working, and the set up is almost the same.

I also have, in settings.py the following:

LOCALE_PATH = (
os.path.join(PROJECT_DIR, "myapp/locale"),
)



> * locale/sk/LC_MESSAGES/django.po:
> ...
> #: forms.py:7
> msgid "Your name"
> msgstr "Vaše meno"
> ...
>
>
Confirm which version of Django you are using? Also, confirm that you are
using
django-admin.py makemessages -l sk to create the po file?



> * compiled into django.mo
>

and django-admin.py compilemessages to make the mo file?


* userproject/settings.py:
> LANGUAGE_CODE = 'sk'
>
> LANGUAGES = (
>('en', 'English'),
>('sk', 'Slovensky'),
> )
> USE_I18N = True
> USE_L10N = True
>
> Displayed form is in english. I tried to copy locale directory to all
> possible places (minicms, minicms/plugins, userproject, ...) but everything
> is only in english :(



Also, when developing, I find that Chromium (on Ubuntu 10.4) for instance,
ignores all the localisation for the computer install default, whereas
Firefox will obey the lang setting (edit->prefs->content->languages). Which
is handy, because I'm monolingual - I can work in Chromium and test in
Firefox.

Try the settings.py:LOCALE_PATH first and let us know. If that doesn't work,
make sure you answer the other questions posed above.

cheers
L.


Lachlan Simpson
Technology Manager
Translation and Interpreting Studies
Monash University, Clayton
Victoria 3800

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Help with localization

2010-07-25 Thread Lachlan Musicman
On Mon, Jul 26, 2010 at 11:16, Martin Tiršel  wrote:

> * userproject/settings.py:
> LANGUAGE_CODE = 'sk'
>
> LANGUAGES = (
>('en', 'English'),
>('sk', 'Slovensky'),
> )
> USE_I18N = True
> USE_L10N = True
>

Gah, my eyes were closed.

Have you also added the appropriate Middleware product?

As you see here:
http://docs.djangoproject.com/en/dev/topics/i18n/deployment/#topics-i18n-deployment
you
need to have soemthing like the following:

MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',)


remember that order is important - that doc page has more info


cheers
L.

Lachlan Simpson
Technology Manager
Translation and Interpreting Studies
Monash University, Clayton
Victoria 3800

+61 3 9905 4221

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Dango-tagging incompatibilities?

2010-08-05 Thread Lachlan Musicman
I am using django-tagging with trunk and am not experiencing any real
problems. Admittedly, I'm not under massive load, but it's working
fine...

cheers
L.

On Fri, Aug 6, 2010 at 08:18, adelein  wrote:
> Has anyone used django-tagging lately with Django 1.1 and above? I am
> starting to use it but saw some comments in stackoverflow about
> incompatibilities. Dont want to go down a dead end.
>
> Appreciate your tips!
>
>
> Thanks,
>
> Adelein
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Translation

2010-08-10 Thread Lachlan Musicman
On Wed, Aug 11, 2010 at 02:43, kostia  wrote:
> Docs and djangobook useless in question of translation. Any other
> guide to read is available?

I would recommend you use Firefox, go to Edit->Preferences->Content,
choose the language of choice at the bottom.

You can't just translate the site and expect it to "jump out" at you -
you actually have to make some sort of locale change on your computer
as well. This Firefox method is one way to do it.

Note that the pages cootetom sent you to imply this, but it's not
explicit, nor is sending you to those pages and expecting you to
extrapolate that information very helpful in this case.

Cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Translation

2010-08-11 Thread Lachlan Musicman
On Thu, Aug 12, 2010 at 03:07, kostia  wrote:
>
> Great. It somehow got working.
>
> I have the next code in the template:
> {% blocktrans with form_type|capfirst as task %}{{ task }} project{%
> endblocktrans %}
>
> Rosetta shows me an error in the left window:
> %(task)s project
>
> And when I try to compilemessages, terminal also shows an error:
> [r...@baikal projector]# python manage.py compilemessages
> processing file django.po in /home/kostia/Documents/Django/projector/
> locale/ru/LC_MESSAGES
> /home/kostia/Documents/Django/projector/locale/ru/LC_MESSAGES/
> django.po:400: a format specification for argument 'task' doesn't
> exist in 'msgstr'
> msgfmt: found 1 fatal error
> processing file django.po in /home/kostia/Documents/Django/projector/
> locale/uk/LC_MESSAGES
> /home/kostia/Documents/Django/projector/locale/uk/LC_MESSAGES/
> django.po:397: a format specification for argument 'task' doesn't
> exist in 'msgstr'
> msgfmt: found 1 fatal error
>
> Any suggestion?

Yep. When you see something like %( word-in-here )s  within the po
file, you are reaquired to keep the %()s - it means that the
"word-in-here" is a variable type string - which is the "format
specification" referred to in the error.
The best example of why this is useful is the date field. Say you have
the sentence:

The date today is 2010/08/12.

The date field is most likely a variable, not set in stone, hence the
format specification. The position of the date field in any particular
language may be different - it may come first or last or in the
middle. Finally, date field syntax are usually set by the locale
already and need to be adhered to in case the user changes it on a
computer by computer basis. In Australia, we use dd/mm/, the
American's use mm/dd/ etc.

Anyway, put the %()s around the relevant word in the msgstr field, and
you should be set to go. I'd help but my Russian and Ukranian aren't
what they used to be :)
cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: forms tutorials

2010-08-11 Thread Lachlan Musicman
These are the more up to date docs:

http://docs.djangoproject.com/en/dev/topics/forms/

Also, in IRC yesterday Mattmcc (I think) dropped this doozy:

http://sprawsm.com/uni-form/

Once you have mastered forms, uni-form should make the css a lot
easier - note the django plugin at the bottom of the page

cheers
L.

On Thu, Aug 12, 2010 at 05:23, Nick  wrote:
> The best option would be to break off of the tutorials for a bit and
> try to build something out on your own. The documentation for forms is
> quite extensive.
>
> I recommend getting comfortable with inlines and formsets
>
> http://docs.djangoproject.com/en/1.1/topics/forms/
>
>
> On Aug 11, 1:39 pm, Jagdeep Singh Malhi 
> wrote:
>> Hi...
>>
>> I done the 
>> tutorialshttp://docs.djangoproject.com/en/dev/intro/tutorial04/#intro-tutorial04
>> for create the form using database.
>>
>> Now i want to study more tutorials/examples which is helpful for me to
>> create the forms using database.
>> if anybody know about the links/websites/other sources related Django
>> forms.
>> Please post.
>>
>> Thanks
>>
>> Regards,
>> Jagdeep Singh
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Django 1.3

2010-08-15 Thread Lachlan Musicman
On Sun, Aug 15, 2010 at 20:38, DjangoRocks  wrote:

> I was wondering if South would be added as part of the standard Django
> release?
>


As I understand it the Django devs have requested it's integration, and the
South dev has responded "I would like the South code to be cleaner and
smarter". I could be wrong about this.

>From the South website:

"Sometime in 2009, it became the most popular of the various migration
alternatives, and seems to have been going strong ever since. While there
have been growing calls to integrate South, or something like it, into
Django itself, such an integration has not yet been made, mostly due to the
relative immaturity of database migration solutions."

*http://south.aeracode.org/docs/about.html#a-brief-history*


cheers
L.


On Aug 2, 1:10 pm, Russell Keith-Magee 
> wrote:
> > On Sun, Aug 1, 2010 at 10:35 PM, mayikmaster  wrote:
> > > hello and thank you for this great project which I have learned so
> > > much. I would like to know what will happen with djanggo 1.3 Where
> > > we've heard.many thanks
> >
> > Formal plans for Django 1.3 have not yet been announced.
> >
> > However, as a rough indication, I would expect to see a 1.3 release at
> > very end of this year (perhaps early next year if schedules run over).
> > There won't be a lot of major new features delivered in Django 1.3;
> > the focus will be on fixing bugs and adding minor features that were
> > missed during the 1.2 development cycle.
> >
> > 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-us...@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-us...@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: Мобильная версия

2010-08-27 Thread Lachlan Musicman
according to google:

I can not understand how best to implement the definition of what a person
gone now, with mobile, and that I need to shove him to the mobile
version?
Maybe someone already implement these moments?


It's a drunk russian beat poet that's lost his or her way, just ignore them.

2010/8/27 Олег Корсак :
> English?
>
> 27.08.2010 04:42, Vanger - irk пишет:
>> не могу понять, как лучше реализовать определение того, что человек
>> зашел сейчас с мобилы, и что мне нужно подсунуть ему мобильную
>> версию ?
>> Может быть кто-то уже реализовывал эти моменты?
>>
>
>



-- 
These simple functions belong to a sub-class known as strictly
dominating functions, meaning that their output is always bigger than
their inputs. A striking fact, known as the complementation theorem,
holds for all such functions. It says there is always an infinite
collection of inputs that when fed into the function will produce a
collection of outputs that is precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Мобильная версия

2010-08-27 Thread Lachlan Musicman
2010/8/27 Lachlan Musicman :
> It's a drunk russian beat poet that's lost his or her way, just ignore them.

That come out wrong on re reading. I didn't mean to offend if I did, apols.

>
> 2010/8/27 Олег Корсак :
>> English?
>>
>> 27.08.2010 04:42, Vanger - irk пишет:
>>> не могу понять, как лучше реализовать определение того, что человек
>>> зашел сейчас с мобилы, и что мне нужно подсунуть ему мобильную
>>> версию ?
>>> Может быть кто-то уже реализовывал эти моменты?
>>>
>>
>>
>
>
>
> --
> These simple functions belong to a sub-class known as strictly
> dominating functions, meaning that their output is always bigger than
> their inputs. A striking fact, known as the complementation theorem,
> holds for all such functions. It says there is always an infinite
> collection of inputs that when fed into the function will produce a
> collection of outputs that is precisely the non-inputs.
> - http://bit.ly/d3Fsrw
>



-- 
These simple functions belong to a sub-class known as strictly
dominating functions, meaning that their output is always bigger than
their inputs. A striking fact, known as the complementation theorem,
holds for all such functions. It says there is always an infinite
collection of inputs that when fed into the function will produce a
collection of outputs that is precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: set utf8 as default database char set

2010-08-31 Thread Lachlan Musicman
On Tue, Aug 31, 2010 at 23:52, Elim Qiu  wrote:

> I just feel kind of redundant to have the same text in and above the
> textfields.


This is a result of the tutorial - they aren't always the same :)



>

And also the odd table layout that makes choice fields and votes' fields so
> apart; and doubt if I did something wrong.
>
> At the moment, I only care about following the tutorial correctly. If you
> think it looks fine, then it's fine and I'll move forward:)
>
> Thanks Karen
>
>
> On Tue, Aug 31, 2010 at 5:10 AM, Karen Tracey  wrote:
>
>> On Tue, Aug 31, 2010 at 3:14 AM, Elim Qiu  wrote:
>>
>>> I'm in tutorial 2. Looks like I did something wrong. Please help. thanks
>>> See the image attached
>>>
>>
>> The image looks fine to me. What do you see that you think is wrong?
>>
>> Karen
>> --
>> http://tracey.org/kmt/
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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-us...@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.
>



-- 
These simple functions belong to a sub-class known as strictly dominating
functions, meaning that their output is always bigger than their inputs. A
striking fact, known as the complementation theorem, holds for all such
functions. It says there is always an infinite collection of inputs that
when fed into the function will produce a collection of outputs that is
precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Does anyone have the completed and fully-working code from the Tutorial?

2010-09-07 Thread Lachlan Musicman
On Wed, Sep 8, 2010 at 04:27, Erskine  wrote:

> After much gnashing of teeth and having looked over the code dozens of
> times I finally realized I was missing one wretched little comma in
> the HttpResponseRedirect return argument.
>

heh. The archetypal "welcome to coding" bug headfsck. I still remember my
first. Damn they suck.


 On Sep 7, 1:26 pm, David De La Harpe Golden
>  wrote:
> > On 07/09/10 16:44, Erskine wrote:
> >
> > > I've spent a few days working through the First App tutorial, and have
> > > mostly got everything working, but I haven't been able to figure out
> > > why I'm getting an extra slash appended after 'polls' when clicking on
> > > the name of the poll
> > > The current URL, polls//, didn't match any of these.
> >
> > Probably you've got a typo in one of your templates, a bit
> > that generates the link to the poll i.e. somewhere you're supposed
> > to have some link like
> >
> > 
> >
> > ... but if the bit in {{ }} evaluated to nothing instead
> > of the id of a poll, you'd get "polls//", you see.
> > That could happen if you typed "pole.id" instead of "poll.id", say.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
These simple functions belong to a sub-class known as strictly dominating
functions, meaning that their output is always bigger than their inputs. A
striking fact, known as the complementation theorem, holds for all such
functions. It says there is always an infinite collection of inputs that
when fed into the function will produce a collection of outputs that is
precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: django-tagging languages and multi fields

2010-09-07 Thread Lachlan Musicman
On Tue, Sep 7, 2010 at 16:39, Henrik Genssen wrote:

> Hi,
>
> has someone a solution for tags in more than one language for the same
> entry?
> I normally use transdb (1) to archive this on char or textfields. But what
> about tags in multi languages for one entry?
>
> Has someone managed to get more than one tag field for a model? e.g. for
> internal and external tagging of an entry...
>
>

I don't know about transdb, but I am using django tagging
http://code.google.com/p/django-tagging/ and ran into the same problem.

On a book model, I wanted a "tag" tag and a "genre" tag. Turns out you can
have more than one, but not in the way I expected.

The way Django tagging is written, tags can be tagged. So I just have the
one "tag" field on the book model, and then I tag some of the tags as
"genre".

Is that what you mean?

L.



> regards
> Hinnack
>
>
> (1) http://code.google.com/p/transdb/
>
> Henrik Genssen
>
> h...@miadi.net
> Tel. 0451/6195650
> Fax. 0451/6195655
>
> miadi GmbH
> Geschäftsführer: Henrik Genssen
> Sitz der Gesellschaft: Beckergrube 2, 23552 Lübeck
> Amtsgericht Lübeck HRB 10223, USt-IdNr DE
> Lieferungen und Leistungen erfolgen ausschließlich auf Grundlage unserer
> allgemeinen Geschäftsbedingungen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
These simple functions belong to a sub-class known as strictly dominating
functions, meaning that their output is always bigger than their inputs. A
striking fact, known as the complementation theorem, holds for all such
functions. It says there is always an infinite collection of inputs that
when fed into the function will produce a collection of outputs that is
precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Language Translation

2010-09-08 Thread Lachlan Musicman
On Wed, Sep 8, 2010 at 17:42, Kenneth Gonsalves  wrote:
> On Wed, 2010-09-08 at 00:32 -0700, hemi19 wrote:
>> Iam new to the django and i want know how can i translate my site
>> language
>> according to the country or any language. suppose if my user selects
>> chinese
>> language then the site should be showed in chinese language or my user
>> selects japanese site should show me japanese language (all the menu
>> items,
>> links etc.,) .Is it done by coding or any other way to get it. Please
>> help
>> me if u know
>
> i18n. Check out the documents on internationalization and localization -
> django has comprehensive support for t range of languages.

Which can be found here

http://docs.djangoproject.com/en/dev/topics/i18n/


-- 
These simple functions belong to a sub-class known as strictly
dominating functions, meaning that their output is always bigger than
their inputs. A striking fact, known as the complementation theorem,
holds for all such functions. It says there is always an infinite
collection of inputs that when fed into the function will produce a
collection of outputs that is precisely the non-inputs.
- http://bit.ly/d3Fsrw

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Conf/locale

2010-11-21 Thread Lachlan Musicman
On Sat, Nov 20, 2010 at 23:29, Tsolmon Narantsogt  wrote:
> Hello fellows.
> I'm using Django 1.1 version. My goals is create multiple language site.
> I make po file
> myprojectname/conf/locale/mn/LC_MESSAGES/django.po
> and some msgid, msgstr.
> But it's don't work.

It's too late in the day to grok the below (and I'm just not good
enough at Django), but I found that you don't need to let users decide
which language that they want to use.

When I'm doing mulitlingual and want to see the results, I use a
different browser: I open firefox, set _firefox_'s default language to
(in my case) Japanese, and then view my site: booyah! there it is in
Japanese. If I surf the web in firefox, everything is in Japanese that
can be, so I need to do my English development in Chromium (or Opera,
IE, etc).

So if you just want to "see" you site in the other languages, to
confirm that it's working, try loading another browser and setting
it's locale to the language you are after.

I hope this helps (or gets me a good talking down because I've done it
wrong :) )
cheers
L.


>
> My index.html
>                {% load i18n %}
> {% get_current_language as LANGUAGE_CODE %}
> {% get_available_languages as LANGUAGES %}
> {% get_current_language_bidi as LANGUAGE_BIDI %}
> 
> 
> 
> {% for lang in LANGUAGES %}
>  {% ifequal request.LANGUAGE_CODE lang.0 %}
> selected
> {% endifequal %}>
> {{ lang.1 }}
> {% endfor %}
> 
> 
> 
> 
>          {% trans "current language" %}: {{ request.LANGUAGE_CODE }}
> My urls.py
>     (r'^i18n/', include('django.conf.urls.i18n')),
> Thanks.
> Tsolmon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



percentage of models given field value?

2010-11-24 Thread Lachlan Musicman
Hola,

Using django 1.2 I wanted to present some statistics on the data that
we have been collecting in our db.

We have source texts with authors, and target texts with their translators.

The target text model has a value "Language".

I get the count of the target texts: all, and then filtered by
language. How would I present each language as a percentage of the
total target text count?

cheers
L.


views.py

def statistics(request):
  """
  collects counts on all models: Source, Target, Authors, Translators
and languages for basic stats page view
  """
  '''
  target text stats
  '''
  target_count = TargetText.objects.all().count()
  target_japanese = TargetText.objects.filter(language="ja").count()
  target_spanish = TargetText.objects.filter(language="es").count()
  target_italian = TargetText.objects.filter(language="it").count()
  target_tradchinese = TargetText.objects.filter(language="zh-cn").count()
  target_simpchinese = TargetText.objects.filter(language="zh-tw").count()
  '''
  translator stats
  '''
  translator_count = Translator.objects.all().count()
  translator_spanish = Translator.objects.filter(language="es").count()
  trans_span_percent = translator_spanish / translator_count
  translator_japanese = Translator.objects.filter(language="ja").count()
  translator_italian = Translator.objects.filter(language="it").count()
  translator_simpchinese = Translator.objects.filter(language="zh-tw").count()
  translator_tradchinese = Translator.objects.filter(language="zh-cn").count()

  source_count = SourceText.objects.all().count()
  author_count = Author.objects.all().count()
  lang_dict = dict(LANGUAGES)
  langs = TargetText.objects.values_list('language',
  flat=True).distinct().order_by('language')
  long_langs = [lang_dict[lang] for lang in langs]
  return render_to_response('library/stats.html', locals())

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: percentage of models given field value?

2010-11-24 Thread Lachlan Musicman
On Thu, Nov 25, 2010 at 13:44, Christophe Pettus  wrote:
>
> On Nov 24, 2010, at 4:37 PM, Lachlan Musicman wrote:
>> Using django 1.2 I wanted to present some statistics on the data that
>> we have been collecting in our db.
>>
>> We have source texts with authors, and target texts with their translators.
>>
>> The target text model has a value "Language".
>>
>> I get the count of the target texts: all, and then filtered by
>> language. How would I present each language as a percentage of the
>> total target text count?
>
> This is a great query to write as SQL, rather than using the ORM (I love the 
> Django ORM, but the right tools for the right job).
>
> Assuming more or less standard Django names, you could return a list of the 
> languages, the total number of texts for each language, and the percentage of 
> the total with something along the lines of:
>
>        SELECT language, COUNT(*), (COUNT(*)/(SELECT COUNT(*) FROM 
> app_targettexts))
>                FROM app_targettexts
>                GROUP BY language
>
> This has the advantage that it only hits the database once.  If you need the 
> grand total, you can either calculate it in the application, or thorw on:
>
>        UNION
>        SELECT 'total', COUNT(*), 1.0 FROM app_targettexts

Thanks Christopher. I've never done raw SQL in Django before. This may
seem like a silly follow up question, but is it standard practice to
put the relevant code, as described by the documentation
(http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
) into views.py?

cheers
L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Django - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Lachlan Musicman
On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> Hi,
>
> I'm wondering what the community's stance on using NULL in Django is?
>
> Say for example you have:
>
>    class Person(models.Model):
>        street_address = models.CharField(max_length=50, blank=True)
>        suburb = models.CharField(max_length=30)
>        postcode = models.IntegerField()
>        state = models.CharField(max_length=3)
>        email = models.EmailField()
>        mobile_phone_number = models.IntegerField(max_length=12)
>        home_phone_number = models.IntegerField(max_length=10,
> null=True, blank=True)
>        work_phone_number = models.IntegerField(max_length=8,
> null=True, blank=True)
>
>       spouse = models.ForeignKey('self', null=True, blank=True)
>       children = models.ManyToManyField('self', null=True,
> blank=True)
>
> For string fields like street_address, I can make these "blank=True",
> and Django will store an empty string if the user leaves it blank.
>
> However, for integer fields like home_phone_number and
> work_phone_number, I've had to make these "null=True" for the case
> where somebody doesn't supply them (i.e. they're meant to be optional,
> mobile is required).
>
> However, is there a better way of handling this case? (assuming I want
> to keep these fields as integers).


Is it possible to know why you would want to keep them as integers?
Given that there are no mathematical functions that you would want to
apply to them


> What about in the case of optional foreign keys (spouse and children)
> - is there a better way of handling these, without using NULLs?

As I understand it, foreign keys are kept in the db as follows:

1. table_Person
2. table_Person_children
3. table_Person_spouse

table 2 has three columns: id, Person, Children
table 3 has three columns: id, Person, Spouse

or something to that effect.

Therefore, if there is no Spouse or Child, there is no entry for
Person in tables 2 or 3.



> Cheers,
> Victor
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: percentage of models given field value?

2010-12-08 Thread Lachlan Musicman
On Thu, Nov 25, 2010 at 16:00, Christophe Pettus  wrote:
>
> On Nov 24, 2010, at 8:13 PM, Lachlan Musicman wrote:
>> Thanks Christopher. I've never done raw SQL in Django before. This may
>> seem like a silly follow up question, but is it standard practice to
>> put the relevant code, as described by the documentation
>> (http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
>> ) into views.py?
>
> Oh, and: Another very logical place to put this is in a custom Manager 
> subclass for the relevant Model; there's documentation on that usage in the 
> docs:
>
>        
> http://docs.djangoproject.com/en/1.2/topics/db/managers/#adding-extra-manager-methods
>

I've successfully got the data I was after, and I've even got it into
the template with success - thankyou!

The problem I now have is that the data returned has the format:

language,number,percent

where language = short language code.

In the template I'd like to represent language in it's long form, but
am having all types of trouble getting it to do so. I have the longs
in a dictionary in my models.py, in my views.py I've created a smaller
dict of long_langs, but how do I then match them in the template?

Here's some of my template attempts:

these proved that the data is coming through to the template
{{ target_stats }}
{# {{ long_langs  }} #}
{#  {{ lang_dict }}  #}

These loops didn't work (for obvious reasons...)

  {% for language, number, percent in target_stats %}
{{ long_lang.foorloop.counter }} {{ number }} {{ percent }} 
  {% endfor %}

and

  {% for language, number, percent in target_stats %}
{{ lang_dict[language] }} {{ number }} {{ percent }} 
  {% endfor %}

there have been a few other attempts - mostly riffs on those
themes...I even tried a
for(for(if))) but nothing came out.

I'm confused about how to get this right

cheers
L.

-- 
"... imagine a puddle waking up one morning and thinking, 'This is an
interesting world I find myself in - an interesting hole I find myself
in - fits me rather neatly, doesn't it? In fact it fits me
staggeringly well, must have been made to have me in it!' This is such
a powerful idea that as the sun rises in the sky and the air heats up
and as, gradually, the puddle gets smaller and smaller, it's still
frantically hanging on to the notion that everything's going to be
alright, because this world was meant to have him in it, was built to
have him in it; so the moment he disappears catches him rather by
surprise."
Douglas Adams

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: percentage of models given field value?

2010-12-08 Thread Lachlan Musicman
On Thu, Dec 9, 2010 at 14:13, Lachlan Musicman  wrote:
> On Thu, Nov 25, 2010 at 16:00, Christophe Pettus  wrote:
>>
>> On Nov 24, 2010, at 8:13 PM, Lachlan Musicman wrote:
>>> Thanks Christopher. I've never done raw SQL in Django before. This may
>>> seem like a silly follow up question, but is it standard practice to
>>> put the relevant code, as described by the documentation
>>> (http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
>>> ) into views.py?
>>
>> Oh, and: Another very logical place to put this is in a custom Manager 
>> subclass for the relevant Model; there's documentation on that usage in the 
>> docs:
>>
>>        
>> http://docs.djangoproject.com/en/1.2/topics/db/managers/#adding-extra-manager-methods
>>
>
> I've successfully got the data I was after, and I've even got it into
> the template with success - thankyou!
>
> The problem I now have is that the data returned has the format:
>
> language,number,percent
>
> where language = short language code.
>
> In the template I'd like to represent language in it's long form, but
> am having all types of trouble getting it to do so. I have the longs
> in a dictionary in my models.py, in my views.py I've created a smaller
> dict of long_langs, but how do I then match them in the template?
>
> Here's some of my template attempts:
>
> these proved that the data is coming through to the template
> {{ target_stats }}
> {# {{ long_langs  }} #}
> {#  {{ lang_dict }}  #}
>
> These loops didn't work (for obvious reasons...)
>
>  {% for language, number, percent in target_stats %}
>        {{ long_lang.foorloop.counter }} {{ number }} {{ percent }} 
>  {% endfor %}
>
> and
>
>  {% for language, number, percent in target_stats %}
>        {{ lang_dict[language] }} {{ number }} {{ percent }} 
>  {% endfor %}
>
> there have been a few other attempts - mostly riffs on those
> themes...I even tried a
> for(for(if))) but nothing came out.
>
> I'm confused about how to get this right


Ignore - I got this within 5 minutes of posting. God.damn.it.



-- 
"... imagine a puddle waking up one morning and thinking, 'This is an
interesting world I find myself in - an interesting hole I find myself
in - fits me rather neatly, doesn't it? In fact it fits me
staggeringly well, must have been made to have me in it!' This is such
a powerful idea that as the sun rises in the sky and the air heats up
and as, gradually, the puddle gets smaller and smaller, it's still
frantically hanging on to the notion that everything's going to be
alright, because this world was meant to have him in it, was built to
have him in it; so the moment he disappears catches him rather by
surprise."
Douglas Adams

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Question!!!

2010-03-28 Thread Lachlan Musicman
On Mar 6, 11:41 am, summea  wrote:

> But do you know if there is any way to set a ManyToManyField's column
> heading to something besides the function name itself?  For example...
> I tried setting verbose_name='authors' in the model... but it didn't
> seem to work as expected.  (No error really, it just didn't change the
> name of the column heading.)
>
> Have you ever needed to change the column name in a view of a
> ManyToManyField?  Anyway... if so, do I need to use something other
> than verbose_name?

Have you tried verbose_name_plural?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Date format errors and date defaults

2012-05-06 Thread Lachlan Musicman
I'm getting an error I don't quite understand how to solve - despite
having

USE_L10N = True
DATE_FORMAT=('j N, Y')
DATE_INPUT_FORMATS=('%d %B %Y')

in my settings.py, the SelectDateWidget still renders in Month/Day/
Year order instead of day/month/year?

Also, is there a way to set the default month and day? Basically if
only the year is known, I'd like the date to default to 1st January,
but I don't want to necessarily have to enter that data?


Cheers
L.

-- 
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.



Generic Views with flair?

2012-05-06 Thread Lachlan Musicman
I've happily worked out how to work @login_required for entries in
views.py, but since the latest tutorial (which I followed) recommends
moving to the Generic Views my code is now like this:

urls.py

...
url(r'^people/$',
ListView.as_view(
queryset=Person.objects.all())),

url(r'^person/(?P\d+)/$',
DetailView.as_view(
model=Person)),
...

How would I set the @login_required for these? Do I have to go back to
writing them up in views.py for this functionality?

Further, the Person model is FK'd to a bunch of other traits like
Certificates, (Work) Experience and Qualifications. They come up fine
in the admin interface, using inlines. I read in the docs that there
are some extra Generic Views so I've added a CreateView and an
UpdateView to my urls.py

url(r'^person/add/$',
CreateView.as_view(
#model=Person)),
template_name='ner/person_create.html',
form_class=PersonForm)),

url(r'^person/(?P\d+)/edit/$',
UpdateView.as_view(
model=Person)),

But now I'm uncertain how I can include the extra traits within these
two functions - they don't appear by default, I'm just getting the raw
Person model. I would like to have it like I can in the admin
interface via the Inlines?


Cheers
L.

-- 
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.



Filter by retirement age?

2012-05-08 Thread Lachlan Musicman
Hola,

I have a model Person with a dob = models.DateField()

I would like to filter by age - in particular only include people less than
60 years old.

I am having no luck getting the syntax right and was looking for pointers?

  queryset=Person.objects.filter(dob__year__gte
= datetime.datetime.today().year-61)

gets me an error like: Join on field 'dob' not permitted. Did you misspell
'year' for the lookup type?

RETIRE_Y = datetime.datetime.today().year-61
...
  queryset=Person.objects.filter(dob__gte =
datetime(RETIRE_Y,1,1,

gives me errors like: 'module' object is not callable

I don't want to create a new field or function on the Person object that
would calculate "age" everyday...

What am I doing wrong/how can I make it right?

cheers
L.

-- 
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: Filter by retirement age?

2012-05-09 Thread Lachlan Musicman
Thanks Tom, but I get an error because timedelta doesn't take years - I've
changed it to weeks=3120 and it works.

Because of that error I've also found another thread discussing the issue:

http://stackoverflow.com/questions/765797/python-timedelta-in-years

I liked the most popular answer's standard lib use of from_date.replace -
is there a norm regards where a small utility like that would be put? It
feels wrong putting it in [views|admin|models|url].py ..?

cheers
L.

On Wednesday, May 9, 2012, Tom Evans wrote:

> On Wed, May 9, 2012 at 12:12 AM, Lachlan Musicman 
> >
> wrote:
> > Hola,
> >
> > I have a model Person with a dob = models.DateField()
> >
> > I would like to filter by age - in particular only include people less
> than
> > 60 years old.
> >
> > I am having no luck getting the syntax right and was looking for
> pointers?
> >
> >   queryset=Person.objects.filter(dob__year__gte
> > = datetime.datetime.today().year-61)
> >
> > gets me an error like: Join on field 'dob' not permitted. Did you
> misspell
> > 'year' for the lookup type?
> >
> > RETIRE_Y = datetime.datetime.today().year-61
> > ...
> >   queryset=Person.objects.filter(dob__gte =
> > datetime(RETIRE_Y,1,1,
> >
> > gives me errors like: 'module' object is not callable
> >
> > I don't want to create a new field or function on the Person object that
> > would calculate "age" everyday...
> >
> > What am I doing wrong/how can I make it right?
> >
>
> You're looking at the data the wrong way. Instead of trying to filter
> out people whose age is over 60, filter out people who were born over
> 60 years ago:
>
> latest_retirees_dob = datetime.datetime.now() -
> datetime.timedelta(years=60)
> still_working = Person.objects.filter(dob__gt=latest_retirees_dob)
> retired = Person.objects.filter(dob__lte=latest_retirees_dob)
>
> Cheers
>
> Tom
>
> --
> 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: Filter by retirement age?

2012-05-09 Thread Lachlan Musicman
Thanks Nikolas - that works.

cheers
L.

On Wednesday, May 9, 2012, Nikolas Stevenson-Molnar wrote:

>  On your second attempt, the problem is that you are trying to call the
> datetime module, not the datetime class. Change it to
> datetime.datetime(...) and you should be fine there.
>
> _Nik
>
> On 5/8/2012 4:12 PM, Lachlan Musicman wrote:
>
> Hola,
>
>  I have a model Person with a dob = models.DateField()
>
>  I would like to filter by age - in particular only include people less
> than 60 years old.
>
>  I am having no luck getting the syntax right and was looking for
> pointers?
>
>queryset=Person.objects.filter(dob__year__gte
> = datetime.datetime.today().year-61)
>
>  gets me an error like: Join on field 'dob' not permitted. Did you
> misspell 'year' for the lookup type?
>
> RETIRE_Y = datetime.datetime.today().year-61
>  ...
>   queryset=Person.objects.filter(dob__gte =
> datetime(RETIRE_Y,1,1,
>
>  gives me errors like: 'module' object is not callable
>
>  I don't want to create a new field or function on the Person object that
> would calculate "age" everyday...
>
>  What am I doing wrong/how can I make it right?
>
>  cheers
> L.
> --
> 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 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com  '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 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com  'django-users%2bunsubscr...@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.



Search in Django

2012-05-09 Thread Lachlan Musicman
Hi,

I want to implement search in my django project.

Looking around, I see lots about Haystack.

I looked at Whoosh for the backend, but then I saw a tutorial for
Djapian/Xapian that made the whole thing look dead simple.

Also, since then I've discovered that Whoosh is lightweight and while
the project is small scale, I'd prefer to use something
sturdier/beefier.

Do people recommend one in particular: Haystack or Djapian?

And if Haystack, which back end do people recommend for a simple
install/set up process, yet with some omph.

Cheers
L.

-- 
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 plugins

2012-06-13 Thread Lachlan Musicman
Hola,

I just watched a video from last year about modifying the Django Admin
interface. I was wondering if people recommend any particular app?

Grappelli and django-admin-tools are both still being developed. Are
there any others and if you prefer one, why?

Am thinking especially in terms of handing over to no technical staff
to do basic admin.

cheers
L.

-- 
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 plugins

2012-06-14 Thread Lachlan Musicman
On Thu, Jun 14, 2012 at 1:20 AM, patrickk  wrote:
> what do you mean with "Grappelli and django-admin-tools are both still being
> developed"?
> both apps have stable releases for quite a while (with grappelli, this is
> even true for a couple of years now).

I was looking for confirmation that they were *actively* developed and
not just getting poked occasionally - I was also looking to see if
there were any others that had flown beneath the radar.

I'd check the commit logs but my connection is too slow to load github

I'll grab both and check them out


cheers
L.

>
> best,
> patrick
>
>
> Am Donnerstag, 14. Juni 2012 00:33:00 UTC+2 schrieb Lachlan Musicman:
>>
>> Hola,
>>
>> I just watched a video from last year about modifying the Django Admin
>> interface. I was wondering if people recommend any particular app?
>>
>> Grappelli and django-admin-tools are both still being developed. Are
>> there any others and if you prefer one, why?
>>
>> Am thinking especially in terms of handing over to no technical staff
>> to do basic admin.
>>
>> cheers
>> L.
>
> --
> 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/-/b3P6Y8Lcd9MJ.
> 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: New to DJANGO

2012-06-24 Thread Lachlan Musicman
On Thu, Jun 21, 2012 at 9:37 PM, LJ  wrote:
> I started out learning Django using the "Writing your first Django app"
> article:
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
> This is a very well-written tutorial that goes through each part in detail.
> Please note, at the bottom of each section there is a link to the next
> section.  There are 3 parts.
> Part 2 shows how to create the urls.py.
> Part 3 shows how to create the views.py.


The tutorial has expanded to 4 lessons and I cannot recommend it
highly enough - is one of the best introductions available for new
users.

I regularly go back to it to look over and keep my eye in.

cheers
L.

-- 
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: Uninstall for clean install

2012-06-24 Thread Lachlan Musicman
Thomas, If you've ever wanted to know why vitualenv is a good idea -
here's a great reason. Since it compartmentalises everything -
packages the whole deal, you can just create a new virtualenv and
start developing.

http://www.arthurkoziel.com/2008/10/22/working-virtualenv/


Cheers
L.


On Sun, Jun 24, 2012 at 5:46 PM, Gethin Llyn ab Alwyn  wrote:
> To answer my own question, if you did it through the package manager try
>
> sudo apt-get purge python-django on the command line
>
> if from tar.gz package, on the command line  change directory to
> /usr/local/lib/python(your version)/dist-packages/ and delete django files
> there using sudo rm django -rf and th Django egg info.
>
> That's how it's done on Ubuntu 12.04
>
>
> On 25 June 2012 01:17, Gethin Llyn ab Alwyn  wrote:
>>
>> How did you install it? Did you do it through apt-get or did you install
>> it through a downloaded tar.gz package from the Django website?
>>
>> On Jun 25, 2012 12:31 AM, "thomasgrzybow...@gmail.com"
>>  wrote:
>>>
>>> I need to uninstall django (on ubuntu) so as to do a clean installation.
>>>  Anybody have a procedure for removing django cleanly?
>>> 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/-/vhtf6u6MEqwJ.
>>> 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.

-- 
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: Same virtual-env for all django projects

2012-07-02 Thread Lachlan Musicman
On Tue, Jul 3, 2012 at 10:52 AM, Smaran Harihar
 wrote:
> Hi Djangoers,
>
> I am using virtual-env for my django project and I wanted to know that is it
> ok to use the same virtual-env for all the django projects on my system?
>
> or do I need to create a virtual-env for every other django project?


Of course you can! It's not necessarily a good idea for production
sites, but it is fine.

Cheers
L.

-- 
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: migration via south for inheritance change -> please help

2012-07-04 Thread Lachlan Musicman
I'd like to know this too - but I think the real answer is "get better
at python" - you are essentially (from what I can tell) in a django
shell when south pops the "not blank, not null but no data" error -
try pulling in some details from fixtures?

cheers
L.

On Thu, Jul 5, 2012 at 2:30 AM, Daniel Walz  wrote:
> ...no one?
>
> regards, mcJack
>
> 2012/7/2 mcJack :
>> Hi all,
>>
>> I've got a problem migrating some changes in the model, so I tried to solve
>> it with south.
>> The situation:
>> I implemented two classes, which share some functionality. Now that I
>> improved a little with python, django and co. I wanted to use inheritance
>> for that issue.
>> The model looks like this:
>>
>> class Foo(models.Model):
>> eggs = models.TextField( null=True, blank=True )
>> plants = models.TextField( null=True, blank=True )
>> carpet = models.IntegerField()
>>
>> class Bar(models.Model):
>> eggs = models.TextField( null=True, blank=True )
>> plants = models.TextField( null=True, blank=True )
>> car = models.IntegerField()
>>
>>
>> And obviously I want to transform to:
>> class Base(models.Model):
>> eggs = models.TextField( null=True, blank=True )
>> plants = models.TextField( null=True, blank=True )
>>
>> class Foo(models.Model):
>> base = models.OneToOneField( 'Base', parent_link=True )
>> carpet = models.IntegerField()
>>
>> class Bar(models.Model):
>> base = models.OneToOneField( 'Base', parent_link=True )
>> car = models.IntegerField()
>>
>> But how can I tell south to fill the super class with the data from the old
>> schema?
>>
>> Can I add this information manually in the created migration script? or is
>> there an option/switch I didn't notice?
>>
>> Any hints are very welcome, thanks a lot
>>
>> mcJack
>>
>> --
>> 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/-/_6CYJ1yqh-sJ.
>> 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.
>
>
>
> --
> Daniel Walz - mcj...@gmail.com
> Bremen, Germany
>
> --
> 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.



Adding more data to Generic Views

2012-07-30 Thread Lachlan Musicman
Hola,

I'm confused about adding extra content to a class based Generic View. I've
read
the docs at
file:///home/datakid/src/django-docs/topics/class-based-views.html
and have written the code accordingly.

I have Person, Certificate, Job and Compensation objects. The last three
all
have an FK (or M2M) back to a (or some) Person(s).

My DetailView subclass (which I've put in views.py - is there a better or
more
correct place for it?)

class PersonDetailView(DetailView):
context_object_name = "person"
model = Person

def get_context_data(self,**kwargs):
#Call the base implementation first to get a context
context = super(PersonDetailView, self).get_context_data(**kwargs)
#Add in a querysets
context['job_list'] = Vacancy.complete.all()
context['certificate_list'] = Certificate.objects.all()
context['claim_list'] = Compensation.objects.all()
return context

But I don't want the full list of Vacancies, Certificates or Claims - I
just
want those that are linked to the person - how can I filter by these? I've
tried
.filter(self.get_id)
.filter(self.request.get_id)
.filter(self.person.get_id)
.filter(self.request.person.get_id)
.filter(applicants__get_id__exact=self.get_id) (in the case of Vacancy) etc

How do I filter by the person object that is already in the context?
I know the answer is simple - I should wait until tomorrow when my brain is
fresher, but I want to finish this off tonight if possible.

Of course, the other thing that I can't help but thinking is that at this
point, the non-generic-view method of urls/views might be a simpler way to
go. While Generic Views are quite versatile,  is there a point at which
they are considered to restricting?

L.

-- 
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 more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Tue, Jul 31, 2012 at 11:15 PM, Karl Sutt  wrote:

> So, in conclusion, Lachlan, you would want to do something like:
>
>  def get_context_data(self,**kwargs):
>> #Call the base implementation first to get a context
>> context = super(PersonDetailView, self).get_context_data(**kwargs)
>> #Add in a querysets
>> context['job_list'] =
>> Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> context['certificate_list'] =
>> Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> context['claim_list'] =
>> Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> return context
>
>
> I have not tested this, but it gives you the idea. You'll want to filter
> the Vacancy, Certificate and Compensation objects by the person's ID.
>

Great - thanks!

L,

-- 
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 more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua wrote:

> On 31-7-2012 6:17, Lachlan Musicman wrote:
>
> > I have Person, Certificate, Job and Compensation objects. The last three
> > all
> > have an FK (or M2M) back to a (or some) Person(s).
> >
>
> So reverse relations.
>

Yep, thanks - with Django I often find I have an idea in my head but don't
know what to call it - and it's often surprising what the developers do
call it, until it makes perfect sense . I'm still waiting for that eureka
moment with reverse urls tbh - I have read the docs on those a dozen times,
and just do not get why they are useful or when you would use them. I guess
I need a local example.


> > def get_context_data(self,**kwargs):
> > #Call the base implementation first to get a context
> > context = super(PersonDetailView,
> self).get_context_data(**kwargs)
> > #Add in a querysets
> > context['job_list'] = Vacancy.complete.all()
> > context['certificate_list'] = Certificate.objects.all()
> > context['claim_list'] = Compensation.objects.all()
>
> You don't need any of these. In your template, simply call:
> {{ person.certificate_set.fieldname }}
>

Yes, I was doing that originally (when there was no Compensation objects),
but I was struggling with only rendering when a set existed - for example,
in my person_detail.html I was rendering from the wrong direction - via the
non-Person object via "related name" fields on the FK.

{% if person.jobs %}
Jobs Applied For
{% for job in person.jobs.all %}

{{ job.title }}, {{
job.organisation }}{% if job.division %}, {{ job.division }}{% endif
%}


Which gives me the problem that I was *actually* trying to solve - how to
only render "Jobs Applied For" - the reason for the if statement - if jobs
have been applied for by that person. It didn't work.

I will try using person.vacancy_set.all now ...



> If you insist on having them available as you do above, they should be:
> context['job_list'] = self.get_object().vacancy_set.all()
> context['certificate_list'] = self.get_object().certificate_set.all()
> context['claim_list'] = self.get_object().compensation_set.all()
>
> Required reading:
> https://docs.djangoproject.com/en/1.4/ref/models/relations/
>
> Also, skipping the tutorial is not recommended:
> <
> https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system
> >
>

I didn't, but I did only skim it, since I've done it before.

> Of course, the other thing that I can't help but thinking is that at this
> > point, the non-generic-view method of urls/views might be a simpler way
> to
> > go. While Generic Views are quite versatile,  is there a point at which
> > they are considered to restricting?
>

*too*


> Not really. The only thing that bugs me about them is that adding extra
> context requires sub-classing so you end up with a views.py that solely
> consists of sub-classed generic views with 3 lines of get_context_data().
>

Ok, thanks. I'm still confused about the usefulness of subclassing, given
that object_set exists? I presuming it's to have the actual objects in the
context, not just a reference to them?

anyway, thanks for hte help
L.

-- 
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 more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Wed, Aug 1, 2012 at 8:45 AM, Lachlan Musicman  wrote:

> On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua wrote:
>
>> On 31-7-2012 6:17, Lachlan Musicman wrote:
>>
>> > I have Person, Certificate, Job and Compensation objects. The last three
>> > all
>> > have an FK (or M2M) back to a (or some) Person(s).
>> >
>>
>
>> You don't need any of these. In your template, simply call:
>> {{ person.certificate_set.fieldname }}
>>
>
> I will try using person.vacancy_set.all now ...
>

Ok - this only works for FK relationships, not for M2M relationships?

cheers
L.

-- 
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.



Created & updated date/time in models

2012-08-08 Thread Lachlan Musicman
Hola,

I've got a bunch of date dependent data that I will need to analyse as
the years go by. So adding create_date and update_date fields seems
like the thing to do.

I go researching I and I see that there are debates about whether
auto_now_add and auto_now are useful or whether they should be hated.
Plus there are various work arounds offered with various degrees of
DRY.

>From what I can see, the admin interface already keeps this data for
each object (exception: no create_date for data imported via fixtures
apparently).

In an effort to reduce duplicating data, how would I go about getting
at that data from within my model's view?

cheers
L.

-- 
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: Created & updated date/time in models

2012-08-09 Thread Lachlan Musicman
On Thu, Aug 9, 2012 at 3:33 PM, Dennis Lee Bieber  wrote:
> On Thu, 9 Aug 2012 09:02:39 +1200, Lachlan Musicman 
> declaimed the following in gmane.comp.python.django.user:
>>
>> From what I can see, the admin interface already keeps this data for
>> each object (exception: no create_date for data imported via fixtures
>> apparently).
>>
> Pardon? So far as I know, if the admin interface is displaying data
> related to a database table (django "model"), then ONLY data in that
> table is displayed. There is no auxiliary table created just for the
> admin interface to store date records.

Ah, sorry - to clarify, I wasn't looking at the table structures - I
was looking at the results from the "history" link on each model's
admin edit form...

cheers
L.

-- 
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: Created & updated date/time in models

2012-08-12 Thread Lachlan Musicman
On Sun, Aug 12, 2012 at 12:06 PM, Melvyn Sopacua  wrote:
> On 8-8-2012 23:02, Lachlan Musicman wrote:
>
>> From what I can see, the admin interface already keeps this data for
>> each object (exception: no create_date for data imported via fixtures
>> apparently).
>
> Three options:
> 1) Add the fields you want to each model
> 2) Bypass django and use triggers to populate a separate table, this can
> be installed as custom SQL [1].
> 3) Implement 2) in django using generic foreign keys [2]. This is
> similar to how the admin is doing it, except that you would have to
> connect a global post_save (and pre_delete?) signal and ignore the
> signal if it applies to the "statistics collecting model". The overhead
> will be noticeable.
>
>> In an effort to reduce duplicating data, how would I go about getting
>> at that data from within my model's view?
>
> For option 1) it should be obvious.
> For option 3) by resolving the content type
> Option 2) requires raw SQL [3].

Bingo, perfect answer - thanks
(number 1 it is)
cheers
L.

-- 
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: New to Django, Admin Page not Loading

2012-08-13 Thread Lachlan Musicman
On Tue, Aug 14, 2012 at 10:04 AM, judy ngai  wrote:
> Here is my urls.py page
>
> from django.conf.urls.defaults import patterns, include, url
> from django.contrib import admin
> admin.autodiscover()
>
>
> urlpatterns = patterns('',
> # Examples:
> # url(r'^$', 'budgetmanager.views.home', name='home'),
> # url(r'^budgetmanager/', include('budgetmanager.foo.urls')),
>
> # Uncomment the admin/doc line below to enable admin documentation:
> # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> # Uncomment the next line to enable the admin:
> # url(r'^admin/', include(admin.site.urls)),
> )

Uncomment the admin in urls.py

from this:

> # Uncomment the next line to enable the admin:
> # url(r'^admin/', include(admin.site.urls)),
> )

to this:
> # Uncomment the next line to enable the admin:
> url(r'^admin/', include(admin.site.urls)),
> )

cheers
L.

> And here is my settings.py
>
> INSTALLED_APPS = (
> 'django.contrib.auth', #an authentication system
> 'django.contrib.contenttypes', #framework for content types
> 'django.contrib.sessions', #a session framework
> 'django.contrib.messages', #a messaging framework
> 'django.contrib.staticfiles', #framework for managing static files
> # Uncomment the next line to enable the admin:
>  'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
>  'django.contrib.admindocs',
> 'budget'
> )
>
> I have sync the database and started the server many times. I got the
> welcome page but when I try to do /amin or /admin/ or /admin/auth , the page
> just does not load. I got stuck on the welcome page. As you can see above
> the django.contrib.admin is uncommented and same with the
> django.contrib.admindocs. On the urls.py admin has been imported. I have
> looked through questions on stackoverflow but still can't find the answer.
> Can someone help me out please?
>
> --
> 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/-/acUEAQK82osJ.
> 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.



Model method represented as non-editable field on object edit page

2012-08-13 Thread Lachlan Musicman
Hola,

I have a Person object with

Class Person(model.Models):
...
def get_id(self):
"""
This returns the worker's reference number, or "worker ID"
Think like a social security number
Not kept in the database as it would be extraneous
The 10 is added for aesthetic reasons only
"""
return self.pk + 10
get_id.short_description = 'ID Number'

And in my admin.py I have the appropriate

list_display = ('__unicode__','birth_place','get_id')

But what I really want to achieve is for the "get_id" function to
appear on each object's edit page as an uneditable field - so that the
data entry staff have a visual reference

Is it possible to do this?

cheers

L.

-- 
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: Django 1.4 admin. Calendar widget appears for DateTimeField but not DateField

2012-08-16 Thread Lachlan Musicman
Grimmus,

You haven't really given us a lot of information to work with.

My suggestion is:

1. Try it in another browser or clear your cache and try again
2. Send some more information, by (for example) using a code inspector
(show source, firebug, etc) to see if the jquery and template code is
in the page at all

Cheers
L.

On Thu, Aug 16, 2012 at 10:40 PM, grimmus  wrote:
> I have checked for missing resources (jquery etc.) but all external assets
> are being loaded correctly. It's just that nothing appears beside the
> textbox for the DateField !
>
> Anyone any ideas why this might be happening ?
>
> 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/-/1PJeTlXPX_4J.
> 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: I LOVE THIS COMMUNITY!

2012-08-21 Thread Lachlan Musicman
+1

On Wed, Aug 22, 2012 at 10:49 AM, Babatunde Akinyanmi
 wrote:
> Amen to that
>
> On 8/21/12, Mario Gudelj  wrote:
>> I just want to tell you guys that you're awesome! I've never seen a
>> community which helps noobs so much and with so few dickheads in it. Good
>> on you!
>>
>> 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.
>>
>>
>
> --
> Sent from my mobile device
>
> --
> 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.



Model ChoiceField?

2012-08-30 Thread Lachlan Musicman
Hi,

I was just wondering if there was any noticeable difference between
the models.ChoiceField() and the models.CharField(max_length=x,)?

In the documentation I have (offline, Django v1.4) a reference to:

/path/django-docs-1.4-en/ref/forms/fields.html#django.forms.ChoiceField.choices

But in the example given at
/path/django-docs-1.4-en/ref/models/fields.html#field-choices they use
the CharField() method.

Is there a discernible difference or is it just for clarity?

cheers
L.

-- 
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: Model ChoiceField?

2012-08-30 Thread Lachlan Musicman
Ok, ignore this email - I've just realised one is a Form field, and
the other is a Model field. Apols for stupid.

Cheers
L.

On Fri, Aug 31, 2012 at 1:09 PM, Lachlan Musicman  wrote:
> Hi,
>
> I was just wondering if there was any noticeable difference between
> the models.ChoiceField() and the models.CharField(max_length=x,)?
>
> In the documentation I have (offline, Django v1.4) a reference to:
>
> /path/django-docs-1.4-en/ref/forms/fields.html#django.forms.ChoiceField.choices
>
> But in the example given at
> /path/django-docs-1.4-en/ref/models/fields.html#field-choices they use
> the CharField() method.
>
> Is there a discernible difference or is it just for clarity?
>
> cheers
> L.

-- 
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: To Use or Not to Use the admin backend

2012-09-03 Thread Lachlan Musicman
On Tue, Sep 4, 2012 at 3:38 AM, Frankline  wrote:
> Hi,
>
> I'm creating a site in Python/Django and feel that the admin backend, as
> good as it is, may not be a one-fit-for-all situations.
>
> My question is this:
>
> Have any of you ever had a need to have a custom admin backend?

Only just yesterday...

> In what example situations would one create his/her own admin backend rather
> than using the default admin panel that ships with Django?

I think it's only recently that the documentation actually reflected
the idea that the Django Admin should be used in production. I did a
very simple site w Django 2 years ago and was mocked in IRC for using
the built in django admin: "you are not doing it right". I'm pretty
thick skinned and ignored the comment, but I think it was usual to
write what you needed rather than let the client use the provided back
end.

Anyway, to the question. Once the models, the intermediate models and
the interactions between all of them start getting sufficiently
complex, you will need to put new forms on front. Theoretically, you
don't want to store a "date" variable more than once for instance -
especially amongst things that are linked. my eg: School student
information system: courses, enrolments, tutorials, timetables,
students, attendance records and marks - the timetables, tutorials and
attendance will all need a date, but you only want one.

Using the provided admin to do this is possible, but it then creates
complex work flows and documentation - putting a new form on front can
smooth it out for users.

> What are the disadvantages of rewriting your own backend?

It's more work, more code, more files = greater complexity, more
places to go wrong.

cheers
L.

> Regards,
> Frank
>
> --
> 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: To Use or Not to Use the admin backend

2012-09-03 Thread Lachlan Musicman
Oh, and I forgot to mention, there's this video:

http://python.mirocommunity.org/video/1861/djangocon-2010-customizing-the

which I watched recently - it's a bit old, but interesting none the less

cheers
L.

-- 
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.



'str' object is not callable in base.py

2012-09-03 Thread Lachlan Musicman
Hi all,

Stumped on this one:


Traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/tafe/timetable/2012-4/

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'tafe',
 'south',
 'crispy_forms')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/handlers/base.py"
in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)

Exception Type: TypeError at /tafe/timetable/2012-4/
Exception Value: 'str' object is not callable

urls.py:
...
  url(r'^timetable/(?P[-\w]+)/$', 'timetable_view'),
...

views.py:
@login_required
def timetable_view(request, slug):
timetable = get_object_or_404(slug=slug)
sessions = timetable.sessions.all()
return 
render_to_response('tafe/timetable_detail.html',{'timetable':timetable,'sessions':sessions})

models.py:

class Session(models.Model):
   ...
   timetable = models.ForeignKey(Timetable, related_name='sessions')
   ...

What am I doing wrong?

cheers
L.

-- 
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: To Use or Not to Use the admin backend

2012-09-04 Thread Lachlan Musicman
On Wed, Sep 5, 2012 at 1:50 AM, Tomas Neme  wrote:
> I've a question about this. I tried to do something like this, but
> using the main capabilities and hacking on the ModelAdmin classes,
> changing the formsets and the like, and reusing as much as possible,
> including of course the admin templates.
>
> Of course, it wasn't possible. I was trying to do something as simple
> as a double-indirection inline, a second-level foreign key, and ended
> up just showing a link to the other model's admin page, creating,
> indeed, a complex workflow where none was needed.
>
> To what extent and how particularly would one need override a specific
> admin page to do this kind of thing? Is reusing the templates at all
> possible if you've customized things? Maybe the templates yes, but the
> ModelAdmin views are impossible, I was in a hurry so I wasn't able to
> do a good diagnosis of what would have been needed to do this.

I don't know either mate - I'm going to have to learn, and probably by
trial and error - there's not a lot of good documentation about this
use case or this need. I presume it's like the man pages, or Deleuze
and Guattari - impregnable to the neophyte, but once you no longer
really need them, they make sense. Is ok, here comes learning!

cheers
L.

-- 
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: 'str' object is not callable in base.py

2012-09-04 Thread Lachlan Musicman
On Tuesday, September 4, 2012, zayatzz wrote:

> From this post i can see this line beeing wrong .
>
> timetable = get_object_or_404(slug=slug)
>
> You also need to give object as one of the parameters for
> get_object_or_404 shortcut: like this :
>
> https://docs.djangoproject.com/en/dev/intro/tutorial03/?from=olddocs#a-shortcut-get-object-or-404
>

Thankyou for pointing this out - it was indeed wrong and has now been
fixed. Unfortunately, it didn't solve the problem.

cheers
L.

-- 
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: 'str' object is not callable in base.py

2012-09-04 Thread Lachlan Musicman
On Wednesday, September 5, 2012, Bill Freeman wrote:

> My best guess is that, for whatever reason, 'timetable_view' in your url
> conf
> has not been converted into the view function.  Try actually importing the
> view in urls.py and putting it as the target of the pattern *without*
> the quotes.
> If this works, then figuring out whether you needed
> 'app_name.timetable_view'
> or some such is where to look.  If it still doesn't work, you may get
> additional
> insights (can you actually import views.py, or does it have a syntax
> error, etc.).


Yes, this was the answer - thanks Bill.

I tried tafe.timetable_view and it didn't work, so I tried

from tafe.views import timetable_view

and it did...

then I realised I needed

'tafe*.views.*.timetable_view'
 as the pattern target.

Thanks for your help
L.

-- 
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.



Override save or other options?

2012-09-10 Thread Lachlan Musicman
Hi All,

Simplistically, I have an event type model (for a "school class") with
a date field.

On saving of the first event, I want to add recurring objects.
Specifics for this project are "up to a latest date" (ie, end of term)
and "recur weekly only" (not daily, monthly, yearly, etc - for the
school's weekly timetable)

I have just tried overriding the save method on the object to auto
create these objects.

def save(self):
   super(Event, self).save()

   last_date = self.term.end_date
   series_date = self.date + datetime.timedelta(7)
   while series_date < last_date:
  super(Session, self).save(date = series_date)

I've realised that this will most probably not make new objects, but
will only update the date on the current object. Quite separately, I'm
also getting keyword argument error on "date".

How would you go about creating a series of events from a single save
press? Should I be using some sort of external system (celery or ???)
or should I write an additional method for the model that does the
auto-creation?

At some point after working this out, I will have a need to delete the
series as well...and I don't even want to think about editing the
series. Let's start with creating a recurring event and I'll work on
that later.

Cheers
L.




-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Override save or other options?

2012-09-11 Thread Lachlan Musicman
On Tue, Sep 11, 2012 at 5:15 PM, Jani Tiainen  wrote:
>
> Rather than creating individual series of events from recurring I would do a
> concept called "recurring event". So it would be just a single event that is
> projected to spesific days as necessary. It requires a slightly more work
> but it's easier to maintain - for example entry would just state:
>
> recurring = True
> frequence = WEEKLY
> start_date = 2012-09-11
> end_date = 2012-12-01
> start_time = 09:00
> end_time = 10:00
>
> Then I would roll out custom non-database concept of "calendar day" that
> would be projected from database using both individual entries and recurring
> entries.
>
> Later on it would be very easy to modify existing recurring events and for
> example add cancellation of single event by creating overriding events
> concept.
>
> This way amount of data will be kept relatively small, it's much easier to
> read and modify. Of course drawback is that you need top level mechanisms to
> work with single calendar entries that map to your database representation.

Great, and obvious, idea - unfortunately a bad fit. Each event needs
to be an object as there are student attendance records and staff
attendance records linked to each individually.

I was thinking about it last night and it occurred to me that instead
of using the admin interface I should just write my own form and then
do the multiple object creation in the view - it makes sense to me,
although I'm sure I've miffed something up.

Other ideas still welcome.

cheers
L.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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, ChoiceFields and import?

2012-09-11 Thread Lachlan Musicman
Hi

Is there anyway to import the choices from my models.py into my
forms.py to prevent code duplication?

At the moment I've got the following, but I'm getting invalid sytax
errors in my forms.py:

models.py :
SESSION_CHOICES = (
(u'0',u'Morning 1'),
(u'1',u'Morning 2'),
(u'2',u'Afternoon 1'),
(u'3',u'Afternoon 2'),
(u'4',u'Evening'),
(u'5',u'Weekend'),
)


forms.py:

from django import forms
from tafe.models import Session, Timetable, Subject
from tafe.models import SESSION_CHOICES

class SessionRecurringForm(forms.Form):
subject = forms.ModelChoiceField(queryset=Subject.objects.all)
timetable =
forms.ModelChoiceField(queryset=Timtables.objects.all.ordered_by('-date')
session_number = forms.ChoiceField(choice=SESSION_CHOICES)


Is what I'm trying to do possible? I feel like I've seen someone do it
before, but it was in an unrelated code snippet, and I've no idea
where I found it...

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Forms, ChoiceFields and import?

2012-09-11 Thread Lachlan Musicman
On Wed, Sep 12, 2012 at 1:35 PM, m1chael  wrote:
> Timtables  should also be  Timetables

Yep - thanks. All good now, you were spot on with the missing parentheses
Cheers
L.

>
>
> On Tue, Sep 11, 2012 at 9:30 PM, m1chael  wrote:
>>
>> it looks like you have a syntax error here:
>>
>> timetable =
>> forms.ModelChoiceField(queryset=Timtables.objects.all.ordered_by('-date')
>>
>> should be:
>>
>> timetable =
>> forms.ModelChoiceField(queryset=Timtables.objects.all.ordered_by('-date'))
>> # added a )
>>
>>
>>
>>
>> On Tue, Sep 11, 2012 at 9:26 PM, Lachlan Musicman 
>> wrote:
>>>
>>> Hi
>>>
>>> Is there anyway to import the choices from my models.py into my
>>> forms.py to prevent code duplication?
>>>
>>> At the moment I've got the following, but I'm getting invalid sytax
>>> errors in my forms.py:
>>> 
>>> models.py :
>>> SESSION_CHOICES = (
>>> (u'0',u'Morning 1'),
>>> (u'1',u'Morning 2'),
>>> (u'2',u'Afternoon 1'),
>>> (u'3',u'Afternoon 2'),
>>> (u'4',u'Evening'),
>>> (u'5',u'Weekend'),
>>> )
>>> 
>>>
>>> forms.py:
>>>
>>> from django import forms
>>> from tafe.models import Session, Timetable, Subject
>>> from tafe.models import SESSION_CHOICES
>>>
>>> class SessionRecurringForm(forms.Form):
>>> subject = forms.ModelChoiceField(queryset=Subject.objects.all)
>>> timetable =
>>> forms.ModelChoiceField(queryset=Timtables.objects.all.ordered_by('-date')
>>> session_number = forms.ChoiceField(choice=SESSION_CHOICES)
>>>
>>>
>>> Is what I'm trying to do possible? I feel like I've seen someone do it
>>> before, but it was in an unrelated code snippet, and I've no idea
>>> where I found it...
>>>
>>> cheers
>>> L.
>>>
>>> --
>>> ...we look at the present day through a rear-view mirror. This is
>>> something Marshall McLuhan said back in the Sixties, when the world
>>> was in the grip of authentic-seeming future narratives. He said, “We
>>> look at the present through a rear-view mirror. We march backwards
>>> into the future.”
>>>
>>> http://www.warrenellis.com/?p=14314
>>>
>>> --
>>> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Override save or other options?

2012-09-11 Thread Lachlan Musicman
On Wed, Sep 12, 2012 at 11:46 AM, Mario Gudelj  wrote:
> I had to do the same thing recently. I had to grab the frequency, interval
> etc. (used rrule for that) and then had to look at the first event instance
> and create multiple instances from that event inside the view. If you create
> a series model and use it as a foreign key in your event to keep on top of
> everything it should work.

You mean it should work with keeping per-date attendance records you mean?

cheers
L.

>
> -m
>
> On 12 September 2012 07:31, Lachlan Musicman  wrote:
>>
>> On Tue, Sep 11, 2012 at 5:15 PM, Jani Tiainen  wrote:
>> >
>> > Rather than creating individual series of events from recurring I would
>> > do a
>> > concept called "recurring event". So it would be just a single event
>> > that is
>> > projected to spesific days as necessary. It requires a slightly more
>> > work
>> > but it's easier to maintain - for example entry would just state:
>> >
>> > recurring = True
>> > frequence = WEEKLY
>> > start_date = 2012-09-11
>> > end_date = 2012-12-01
>> > start_time = 09:00
>> > end_time = 10:00
>> >
>> > Then I would roll out custom non-database concept of "calendar day" that
>> > would be projected from database using both individual entries and
>> > recurring
>> > entries.
>> >
>> > Later on it would be very easy to modify existing recurring events and
>> > for
>> > example add cancellation of single event by creating overriding events
>> > concept.
>> >
>> > This way amount of data will be kept relatively small, it's much easier
>> > to
>> > read and modify. Of course drawback is that you need top level
>> > mechanisms to
>> > work with single calendar entries that map to your database
>> > representation.
>>
>> Great, and obvious, idea - unfortunately a bad fit. Each event needs
>> to be an object as there are student attendance records and staff
>> attendance records linked to each individually.
>>
>> I was thinking about it last night and it occurred to me that instead
>> of using the admin interface I should just write my own form and then
>> do the multiple object creation in the view - it makes sense to me,
>> although I'm sure I've miffed something up.
>>
>> Other ideas still welcome.
>>
>> cheers
>> L.
>>
>>
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>>
>> --
>> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



ViewDoesNotExist !?!?! It certainly does....

2012-09-11 Thread Lachlan Musicman
Hola

As per subject - I'm getting ViewDoesNotExist errors on a view that does exist.

I've checked the spelling, indenting and it all seems legit.

If I comment out the two lines that call the view in question from
urls.py, everything is back to normal.
---
tafe/urls.py

from django.conf.urls import patterns, url
from django.views.generic import DetailView, ListView
from tafe.models import Student, Subject, Enrolment, Course, Grade, Timetable

urlpatterns = patterns('tafe.views',
#url(r'^$', 'index'),
url(r'^$', ListView.as_view(queryset=Subject.objects.all()
...
   url(r'^session/create/$', 'session_create'),
)

tafe/views.py


from tafe.models import Session
from tafe.forms import SessionRecurringForm
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
import datetime

def session_create(request):

form = SessionRecurringForm()

return render_to_response('tafe/session_create.html',{'form':form,})



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: ViewDoesNotExist !?!?! It certainly does....

2012-09-11 Thread Lachlan Musicman
Grrr - sorry sent before I was finished.

tafe/views.py

# Create your views here.

from tafe.models import Session
from tafe.forms import SessionRecurringForm
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
import datetime

def session_create(request):

form = SessionRecurringForm()
return render_to_response('tafe/session_create.html',{'form':form,})


The note is "error during template rendering" base.html, at line 35:

{% url 'django-admindocs-docroot' as docsroot %}

Note that as soon as I exclude the url in question it all comes up roses.



L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: ViewDoesNotExist !?!?! It certainly does....

2012-09-12 Thread Lachlan Musicman
On Wed, Sep 12, 2012 at 6:19 PM, Sergiy Khohlov  wrote:
>  add to urls
>  from tafe.views import session_create

Thanks. I actually found this solution late late last night while
offline, buried deep in the docs:
/PATH/django-docs-1.4-en/topics/http/urls.html#passing-callable-objects-instead-of-strings

I'm still confused about why that was necessary, or why the string
didn't work, but am happy that it works.

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Problem Accessing Admin Pages

2012-09-13 Thread Lachlan Musicman
On Fri, Sep 14, 2012 at 7:40 AM, bml1rules  wrote:
> Hey Guys!
>
> I am the webmaster of a Django database and I recently ran into a snag. We
> have an admin section with about 15 privileges. All of a sudden, almost all
> of them are gone. I've tried getting to them by typing in the url, but it
> just takes me back to the main page. However, the pages are still there and
> it just redirects me. I know this isn't much information, but does anyone

If  "it just redirects me" implies that there are other accounts that
*aren't* being redirected, try logging into one of those (admin level)
accounts?

if "it just redirects me" implies 'and there seems to be nothing I can
do', you might need to look into the db via some other method eg:
manage.py shell/phpmyadmin/mysql@command line...

Cheers
L.


> have any idea what I could do to fix this problem?
>
> 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/-/bzAJxJAa3ecJ.
> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
Hi,

I'm getting blank get_absolute_url problems that I just can't solve. I
can get to an object by actually visiting the url that would be
constructed - I've checked that: app/session/year/month/day/slug

models.py:
class Session(models.Model):
...
@models.permalink
def get_absolute_url(self):
return ('session_view', (), {
'year': self.date.year,
'month': self.date.month,
'day': self.date.day,
'slug': self.slug})

As you can see from the template snippet below, I'm printing out all
that makes up the url, and am getting correct results, except for
get_absolute_url

template:
{% for x in session %}
{{
x.subject.name }} {{ x.date.year }} {{ x.date.month }} {{
x.date.day}} {{ x.slug }}

I'm importing the session_view
urls.py:

from tafe.views import session_create, session_view, timetable_daily_view
...
url(r'^session/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P[-\w]+)/$',
session_view),

And the view seems to be properly constructed - I've got debug on, and
I'm getting the page I expected rendering. It's only the
get_absolute_url that's coming back blank.

views.py
@login_required
def session_view(request, year, month, day, slug):
   req_date = datetime.date(int(year), int(month), int(day))
   session = get_object_or_404(Session, slug=slug, date=req_date)

   return render_to_response('tafe/session_detail.html',{'session':session})


I've even checked that the objects have the slugs as per expected in
the admin interface (although visiting the address that the g_a_u
should be returning works, so that was already a given.)

Any ideas? Any tips on where to start looking?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
On Fri, Sep 14, 2012 at 1:38 PM, Russell Keith-Magee
 wrote:
> On Fri, Sep 14, 2012 at 9:07 AM, Lachlan Musicman  wrote:
>> Hi,
>>
>> I'm getting blank get_absolute_url problems that I just can't solve. I
>> can get to an object by actually visiting the url that would be
>> constructed - I've checked that: app/session/year/month/day/slug
> …
>> And the view seems to be properly constructed - I've got debug on, and
>> I'm getting the page I expected rendering. It's only the
>> get_absolute_url that's coming back blank.
>
> Something is going wrong in the reversing process, which is raising an
> exception, which is silently swallowed by the get_absolute_url call.
> The usual culprit is that either the URL pattern isn't matching what
> you think, or the object values you're passing into the reversal
> process aren't what you think they are.
>
> My suggestion -- open up a shell, and try making manual calls to
> reverse(). This will show you whether the problem is with the URL
> pattern, or with the data from the object.

Ok - I appreciate your quick and learned response. Unfortunately I'm
not as deep as you are and am still struggling with how the shell
actually works thoroughly, despite a number of attempts.

First: I'm not using reverse explicitly - I did leave a lot of non
useful code out of my post. Should I be importing the url reverse
function somewhere?

Second: if it's happening under the hood, which I expect is the case,
is there an easy way from within the shell to use the data I have
without having to import everything? Previous attempts have stalled at
"hey where is everything? Isn't settings/db/models imported? etc" Am
searching for django shell examples/howtos and revisiting the tutorial
in other tabs. Unfort am on very limited bandwidth connection (in
Kiribati, via satellite, semi regular brown/black outs).

My own thoughts have converged on "I presume if I wrote tests like
every normal dev then this would be a lot easier. Must learn tests.
Sometime soon."

> Next step; put some debug into get_absolute_url itself -- make a
> manual call to reverse inside get_absolute_url, and catch/print any
> exception that is raised.

Directly into the Django code? Ok. I can do that. I'm glad the
weekends coming and that I have the django and py docs in offline
html.

> Hopefully, that should give you enough detail as to the source of the problem.

Really appreciate your help.

L.


>
> Russ %-)
>
> --
> 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.
>



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
On Fri, Sep 14, 2012 at 2:05 PM, Lachlan Musicman  wrote:
> On Fri, Sep 14, 2012 at 1:38 PM, Russell Keith-Magee
>> Something is going wrong in the reversing process, which is raising an
>> exception, which is silently swallowed by the get_absolute_url call.
>> The usual culprit is that either the URL pattern isn't matching what
>> you think, or the object values you're passing into the reversal
>> process aren't what you think they are.
>>
>> My suggestion -- open up a shell, and try making manual calls to
>> reverse(). This will show you whether the problem is with the URL
>> pattern, or with the data from the object.


Ok, this is what I got from where I'm up to in my learn-djshell-quickly:

>>> s = 
>>> Session.objects.filter(slug='mechanical-tools-morning-2').get(date=datetime.date.today)
>>> s.session_number
u'1'
>>> s.date
datetime.date(2012, 9, 14)
>>> s.slug
u'mechanical-tools-morning-2'
>>> s.get_absolute_url()
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/utils/functional.py",
line 11, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/db/models/base.py",
line 883, in get_absolute_url
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' %
(opts.app_label, opts.module_name), func)(self, *args, **kwargs)
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/db/models/__init__.py",
line 35, in inner
return reverse(bits[0], None, *bits[1:3])
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 476, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix,
*args, **kwargs))
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 396, in _reverse_with_prefix
"arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'session_view' with arguments '()' and
keyword arguments '{'year': 2012, 'slug':
u'mechanical-tools-morning-2', 'day': 14, 'month': 9}' not found.


How do I call reverse in the shell? Import it and...?

reverse(s)?

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
> How do I call reverse in the shell? Import it and...?
>
> reverse(s)?

Gah, should have tried that before sending:

>>> from django.core.urlresolvers import reverse
>>> reverse(s)
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 476, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix,
*args, **kwargs))
  File 
"/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 362, in _reverse_with_prefix
raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
NoReverseMatch: Error importing 'Friday, Morning 2, Mechanical Tools':
'Session' object has no attribute 'rindex'.

Ok, we are getting somewherebut google doesn't turn up anything
that I understand/looks applicable?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
On Fri, Sep 14, 2012 at 2:47 PM, Lachlan Musicman  wrote:
>> How do I call reverse in the shell? Import it and...?
>>
>> reverse(s)?
>
> Gah, should have tried that before sending:
>
>>>> from django.core.urlresolvers import reverse
>>>> reverse(s)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
> line 476, in reverse
> return iri_to_uri(resolver._reverse_with_prefix(view, prefix,
> *args, **kwargs))
>   File 
> "/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
> line 362, in _reverse_with_prefix
> raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
> NoReverseMatch: Error importing 'Friday, Morning 2, Mechanical Tools':
> 'Session' object has no attribute 'rindex'.
>
> Ok, we are getting somewherebut google doesn't turn up anything
> that I understand/looks applicable?


Have managed to solve the problem by changing my urls.py to:
url(r'^session/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P[-\w]+)/$',
session_view, name='session_view'),

(cf urls.py from the OP)
url(r'^session/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P[-\w]+)/$',
session_view),

I'm confused about what's happening here - but I'm glad it's working.

Thanks for the pointers.

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: get_absolute_url is returning '' instead of url

2012-09-13 Thread Lachlan Musicman
On Fri, Sep 14, 2012 at 2:53 PM, Russell Keith-Magee
 wrote:
> On Fri, Sep 14, 2012 at 10:47 AM, Lachlan Musicman  wrote:
>>> How do I call reverse in the shell? Import it and...?
>>>
>>> reverse(s)?
>>
>> Gah, should have tried that before sending:
>>
>>>>> from django.core.urlresolvers import reverse
>>>>> reverse(s)
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File 
>> "/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
>> line 476, in reverse
>> return iri_to_uri(resolver._reverse_with_prefix(view, prefix,
>> *args, **kwargs))
>>   File 
>> "/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/urlresolvers.py",
>> line 362, in _reverse_with_prefix
>> raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
>> NoReverseMatch: Error importing 'Friday, Morning 2, Mechanical Tools':
>> 'Session' object has no attribute 'rindex'.
>>
>> Ok, we are getting somewherebut google doesn't turn up anything
>> that I understand/looks applicable?
>
> What's the value of "s" that you're passing to reverse? Reverse takes
> the same arguments as the return value of get_absolute_url() -- i.e.,
> a string URL label, plus a dictionary of kwargs:
>
>>>> reverse('my-url-name', kwargs={'arg1': 'value1'})
>
> The error you're reporting looks like you're passing something other
> than a string into reverse.

I was passing the object into reverse(), not the string...ah newbie
mistakes, they litter the ground around me.

You saw the "problem solved" email? I needed to name the entry in the urls.py...

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Abstract classes and inhertience

2012-09-16 Thread Lachlan Musicman
Hola,

I have an abstract base class, Person, with three children:
Applicants, Students and Staff.

I have two questions.

As per docs 
($PATH/topics/db/managers.html#custom-managers-and-model-inheritance)
I have three managers for the Abstract class:

people = models.Manager()
men = MaleManager()
women = FemaleManager()

with the appropriate definitions.

For some reason, I can't get

.men.all() or .women.all() to work. Any tips?

Secondly, I want the dob and gender to be using special widgets, so in
admin.py I have:

class PersonAdminForm(ModelForm):
class Meta:
model = Person
widgets = {
'dob': SelectDateWidget(),
'gender': RadioSelect(),
}

but then when I add the form to the StudentAdminForm or
ApplicantAdminForm, it fails on the first field that's not in Person.

Is there anyway to have a generic admin form?

cheers
L.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Confused by BooleanField

2012-09-18 Thread Lachlan Musicman
Hola,

I've written a form that has two BooleanFields on it.

They render as text boxes on the page, which is great.

All my initial testing included checking the boxes for the two
BooleanFields as this is the major use case.

I just did a test in which I didn't check the boxes, and I'm getting
"This field is required" errors.

I'm confused. I understand the whole Blank=True, null=True concepts,
but these two fields aren't within models - they are used for
decision/flow control within the saving of a model...

Finally, if it's a BooleanField, it should be able to represent on/off
- so *not* ticking the box would indicate off, wouldn't it?

What am I doing wrong here?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: date display problem?

2012-09-18 Thread Lachlan Musicman
On Wed, Sep 19, 2012 at 2:34 PM, Navnath Gadakh  wrote:
> i have post date variable to view? but when i retrieve date from database .
> not displaying on browser

We need more information than that - do you mean it's not displaying
in a form, in a regular template or in the admin pages?

And how are you referencing it? Send us the relevant code to look at?

Cheers
L.

>
> --
> 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/-/t7LK3gY0Ib0J.
> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Confused by BooleanField

2012-09-18 Thread Lachlan Musicman
Ignore - I've found the documentation. PATH/ref/forms/fields.html#booleanfield

required=False

cheers
L.

-- 
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: date display problem?

2012-09-18 Thread Lachlan Musicman
 On Wed, Sep 19, 2012 at 3:51 PM, Navnath Gadakh
 wrote:
> model
>class Offer(models.Model):
> effective_date = models.DateField()
> expiration_date = models.DateField()

Nothing wrong here

> view.py
> HTML = HTML + ""
> HTML = HTML + "Offer Description :
> "+offer.description+""
> HTML = HTML + "Coupon Number :
> "+coupon_no.coupon_detail+""
> HTML = HTML + "Effective Date :
> "+str(offer.effective_date)+""
> HTML = HTML + "Expiration Date :
> "+str(offer.expiration_date)+""
> HTML = HTML + ""
> HTML = HTML + ""
>
> at the time of create offer i print variable for expiration and effective
> date in view it worked fine.
> but in temlate it did't other fields displays.
> effective date and expiration date not displaying on browser..


My django isn't good enough to quiet understand your view, but since
you have the offer object there in the view, why don't you pass it to
the template via

render_to_response('/path/to/template.html',{'offer':offer})

And then in your template path/to/template.html

you just need to use the variable

{{ offer.effective_date }}

for instance?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: date display problem?

2012-09-19 Thread Lachlan Musicman
On Wed, Sep 19, 2012 at 10:19 PM, Navnath Gadakh
 wrote:
> i am fetching multiple rows?
>   i have already used
>   for offer in offers:
>   print offer.effective _date
> but didnt work.my code is
>  my_offers =
> Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True)
> for offer in my_offers:
> print offer.effective_date
>
> HTML = HTML + ""
> HTML = HTML + "Offer Description :
> "+offer.description+""
> HTML = HTML + "Coupon Number :
> "+coupon_no.coupon_detail+""
> HTML = HTML + "Effective Date :
> "+str(offer.effective_date)+""
> HTML = HTML + "Expiration Date :
> "+str(offer.expiration_date)+""
> HTML = HTML + "Experience Points :
> "+str(offer.experience_points)+""
> HTML = HTML + "Discount :
> "+str(offer.discount)+""
> #HTML = HTML + "Offer Date :
> "+str(coupon_no.date_of_offer)+""
>
> HTML = HTML + ""
> HTML = HTML + ""

I'm still confused about the HTML string you have here, but anyway,
have you tried either checking that
Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True) is
returning something in the shell or adding a __unicode__(self) and
then

Offer.objects.filter(offer_id=coupon.offer_id_id,is_active=True)
 for offer in my_offers:
 print offer

to check that your filter is working?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Strange rendering behaviour in template/user/auth

2012-09-20 Thread Lachlan Musicman
Hola,

I've noticed for a while that my home/index page wasn't registering
the {{ user }} tag when rendering the page: there was no "Welcome
Username. Change password / Log out" in the top right corner, and the
link to the admin interface that I'd put in the breadcrumbs for logged
in users wouldn't appear.

But that was the only page - every other page showed it fine - so I
wasn't too concerned, and gave it a low priority to fix it.

FWIW the whole site requires authentication (checked and confirmed in
another browser) - so Django knew I was auth'd - it just chose to
ignore some of the base.html

Yesterday I added some thematic changes - a little js and css, plonked
it in path/project/app/static/{js|css} as advised in docs and added
them to the base template with {{ STATIC_URL }}.

Suddenly the lack of auth recognition on some pages (turns out it was
more than one) is noticeable, because the graceful degrading of the
js/css is appalling enough to make it stick out. In particular, when I
"inspected element" I saw that the {{ STATIC_URL }} wasn't being
expanded - the resources were failing on bad paths.

I've tracked everything down that could be the problem - I've
confirmed half a dozen times that the pages in question are extending
the correct base_site.html, which is extending the correct base.html,
I even tried sending the request context in render_to_response with no
luck.

It was only this morning while doing some triage that I realised that
the pages without proper auth (no details in top right corner) where
also the ones with the wonky templating.

Any clues on what I'm doing wrong or new ways to track down where the
mistake is?

Cheers
L.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Strange rendering behaviour in template/user/auth

2012-09-20 Thread Lachlan Musicman
On Fri, Sep 21, 2012 at 10:29 AM, hevok  wrote:
> Hola Lachlan,
> Are you passing the `context_instance=RequestContext(request)` to all
> templates? It should provide the user tag.

Hi Hevok,

Thanks for the reply.

I did attempt to merely pass the request:

@login_required
def index(request):
"""
If users are authenticated, direct them to the main page.
Otherwise take them to the login page.
"""
daily_sessions = []

for session in range(4):
daily_sessions.append([])
daily_sessions[session] =
Session.objects.filter(date=today).filter(session_number=session)

return 
render_to_response('tafe/timetable_today_detail.html',{'daily_sessions':daily_sessions,
'request':request})

but that didn't work.

I pass the RequestContext(request) for the forms I wrote to satisfy
CSRF stuff - I guess I just add something similar?

...OK, I just added exactly the same as for the CSRF and it worked -
thanks Hevok!

cheers
L.



>
> Bests,
> Hevok
>
>
> On Friday, September 21, 2012 12:20:04 AM UTC+2, Lachlan Musicman wrote:
>>
>> Hola,
>>
>> I've noticed for a while that my home/index page wasn't registering
>> the {{ user }} tag when rendering the page: there was no "Welcome
>> Username. Change password / Log out" in the top right corner, and the
>> link to the admin interface that I'd put in the breadcrumbs for logged
>> in users wouldn't appear.
>>
>> But that was the only page - every other page showed it fine - so I
>> wasn't too concerned, and gave it a low priority to fix it.
>>
>> FWIW the whole site requires authentication (checked and confirmed in
>> another browser) - so Django knew I was auth'd - it just chose to
>> ignore some of the base.html
>>
>> Yesterday I added some thematic changes - a little js and css, plonked
>> it in path/project/app/static/{js|css} as advised in docs and added
>> them to the base template with {{ STATIC_URL }}.
>>
>> Suddenly the lack of auth recognition on some pages (turns out it was
>> more than one) is noticeable, because the graceful degrading of the
>> js/css is appalling enough to make it stick out. In particular, when I
>> "inspected element" I saw that the {{ STATIC_URL }} wasn't being
>> expanded - the resources were failing on bad paths.
>>
>> I've tracked everything down that could be the problem - I've
>> confirmed half a dozen times that the pages in question are extending
>> the correct base_site.html, which is extending the correct base.html,
>> I even tried sending the request context in render_to_response with no
>> luck.
>>
>> It was only this morning while doing some triage that I realised that
>> the pages without proper auth (no details in top right corner) where
>> also the ones with the wonky templating.
>>
>> Any clues on what I'm doing wrong or new ways to track down where the
>> mistake is?
>>
>> Cheers
>> L.
>>
>>
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>
> --
> 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/-/uYEguNGN3CsJ.
> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Strange rendering behaviour in template/user/auth

2012-09-20 Thread Lachlan Musicman
On Fri, Sep 21, 2012 at 11:18 AM, hevok  wrote:
> Hiya L,
> Your are welcome!
>
> It is not obvious from the tutorial, but RequestContext as its name suggests
> also passes the request context to the template. The context_instance uses
> the auth middleware context processor and provides the user in the view. You
> could also refer to `{{ request.user }}` in the template, but I wouldn't
> recommend it. RequestContext automatically populates everything for you with
> nice variable names.

Yeah, I was just thinking about how I can know enough about Django to
articulate my problem, but not to solve it.

Turns out that the important documentation in this regard is not filed
under R but under D (for django.template.RequestContext):

/path/django-docs-1.4-en/ref/templates/api.html#django.template.RequestContext

And the really important documentation is in the "note".

There's no denying documentation is hard, that Django has excellent
documentation and that making the tutorial (which is fantastic) simple
enough for new users but covering enough ground to get someone started
is a delicate balancing act.

I feel like this needs to be better placed, or to have better
examples. Or maybe that's exactly what the list/IRC is for :)

Cheers
L.


>
> Cheers,
> Hevok
>
>
>
> On Friday, September 21, 2012 12:50:13 AM UTC+2, Lachlan Musicman wrote:
>>
>> On Fri, Sep 21, 2012 at 10:29 AM, hevok  wrote:
>> > Hola Lachlan,
>> > Are you passing the `context_instance=RequestContext(request)` to all
>> > templates? It should provide the user tag.
>>
>> Hi Hevok,
>>
>> Thanks for the reply.
>>
>> I did attempt to merely pass the request:
>>
>> @login_required
>> def index(request):
>> """
>> If users are authenticated, direct them to the main page.
>> Otherwise take them to the login page.
>> """
>> daily_sessions = []
>>
>> for session in range(4):
>> daily_sessions.append([])
>> daily_sessions[session] =
>> Session.objects.filter(date=today).filter(session_number=session)
>>
>> return
>> render_to_response('tafe/timetable_today_detail.html',{'daily_sessions':daily_sessions,
>> 'request':request})
>>
>> but that didn't work.
>>
>> I pass the RequestContext(request) for the forms I wrote to satisfy
>> CSRF stuff - I guess I just add something similar?
>>
>> ...OK, I just added exactly the same as for the CSRF and it worked -
>> thanks Hevok!
>>
>> cheers
>> L.
>>
>>
>>
>> >
>> > Bests,
>> > Hevok
>> >
>> >
>> > On Friday, September 21, 2012 12:20:04 AM UTC+2, Lachlan Musicman wrote:
>> >>
>> >> Hola,
>> >>
>> >> I've noticed for a while that my home/index page wasn't registering
>> >> the {{ user }} tag when rendering the page: there was no "Welcome
>> >> Username. Change password / Log out" in the top right corner, and the
>> >> link to the admin interface that I'd put in the breadcrumbs for logged
>> >> in users wouldn't appear.
>> >>
>> >> But that was the only page - every other page showed it fine - so I
>> >> wasn't too concerned, and gave it a low priority to fix it.
>> >>
>> >> FWIW the whole site requires authentication (checked and confirmed in
>> >> another browser) - so Django knew I was auth'd - it just chose to
>> >> ignore some of the base.html
>> >>
>> >> Yesterday I added some thematic changes - a little js and css, plonked
>> >> it in path/project/app/static/{js|css} as advised in docs and added
>> >> them to the base template with {{ STATIC_URL }}.
>> >>
>> >> Suddenly the lack of auth recognition on some pages (turns out it was
>> >> more than one) is noticeable, because the graceful degrading of the
>> >> js/css is appalling enough to make it stick out. In particular, when I
>> >> "inspected element" I saw that the {{ STATIC_URL }} wasn't being
>> >> expanded - the resources were failing on bad paths.
>> >>
>> >> I've tracked everything down that could be the problem - I've
>> >> confirmed half a dozen times that the pages in question are extending
>> >> the correct base_site.html, which is extending the correct base.html,
>> >> I even tried sending the request context in render_to_response with no

Re: How to extend the TextField in Django?

2012-09-20 Thread Lachlan Musicman
What you are looking for is called a WYSIWYG editor widget - there are a
couple of extentions/plugins lying around:

http://djangosnippets.org/snippets/1705/
or
http://blog.bixly.com/post/22376374604/django-tinymce-a-wysiwyg-editor-for-django
or
https://github.com/pydanny/django-wysiwyg/
or
http://www.djangopackages.com/grids/g/wysiwyg/

Cheers
L.


On Fri, Sep 21, 2012 at 2:19 PM, Scarl  wrote:

>
> 
>
> I want to extend the textfield like this, could anyone help me? 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/-/JqQJ8v6SH88J.
> 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.
>



-- 
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: A lots of foreign keys - Django Admin

2012-09-24 Thread Lachlan Musicman
I'm not an expert on this matter, but I did read about list_select
related recently:

/path/django-docs-1.4-en/ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_select_related

which links to select related:

django-docs-1.4-en/ref/models/querysets.html#django.db.models.query.QuerySet.select_related

which talks about using the depth keyword to minimise the level the db goes to:

"Usually, using select_related() can vastly improve performance
because your app can avoid many database calls. However, in situations
with deeply nested sets of relationships select_related() can
sometimes end up following "too many" relations, and can generate
queries so large that they end up being slow.

In these situations, you can use the depth argument to
select_related() to control how many "levels" of relations
select_related() will actually follow"

Hope this helps!

cheers
L.


On Tue, Sep 25, 2012 at 11:29 AM, rentgeeen  wrote:
> Also just found out when I remove Foreign Keys from admin.py from
> "list_display", it works blazing fast:
>
>
> class ClientAdmin(admin.ModelAdmin):
>
>list_display = ('title',)
>
> admin.site.register(Client, ClientAdmin)
> class CategoryAdmin(admin.ModelAdmin):
>
>list_display = ('client', 'title',)
>
> admin.site.register(Category, CategoryAdmin)
> class SubcategoryAdmin(admin.ModelAdmin):
>
>list_display = ('client', 'category', 'title', )
>
> admin.site.register(Subcategory, SubcategoryAdmin)
> class ProjectAdmin(admin.ModelAdmin):
>
>list_display = ('client', 'category', 'subcategory', 'title', )
>
> admin.site.register(Project, ProjectAdmin)
> class TypeAdmin(admin.ModelAdmin):
>
>list_display = ('client', 'title', )
>
> admin.site.register(Type, TypeAdmin)
> class PageAdmin(admin.ModelAdmin):
>   list_display = ('client', )
>
> admin.site.register(Page, PageAdmin)
>
> FOREIGN KEYS cannot be in list_display? How to optimize them?
>
> On Monday, 24 September 2012 19:17:45 UTC-4, rentgeeen wrote:
>>
>> Have a SQL problem, adding this model all works correctly, the problem is
>> in ADMIN.
>>
>> When I add the data just few to each table, by clicking on TYPE & PAGE in
>> ADMIN the page is loading so slow, installed debug_toolbar and SQL took 17
>> seconds for the TYPE. When I tried the PAGE it gave me timeout, my question
>> is what is wrong with my model? Is it constructed bad?
>>
>> My goal is this lets say example:
>>
>> www.example.com/audi/4doors/s4/sport/red/audi-url
>>
>> basically all 6 urls are dynamic that I would specify in the each table
>> and would be in the PAGE as dropdowns also in others. What is the optimal
>> way to do that or optimize the model?
>>
>> Here is a screenshot of TYPE page loading:
>>
>> screenshot: http://cl.ly/image/2931040E0t35
>>
>> Records:
>>
>> auto_client = 3 rows
>>
>> auto_category = 2 rows
>>
>> auto_subcategory = 2 rows
>>
>> auto_project = 5 rows
>>
>> auto_type = 2 rows
>>
>> auto_page = 0 - because cliking on auto_page it times out because of SQL
>> query. Basically togehter like 14 records thats nothing :)
>>
>> here is also mysql query in PHPmyadmin: cl.ly/image/2S320h3d0P0J 17
>> seconds
>>
>> Please help thanks
>>
>>
>> from django.db import models
>>
>>
>> class Client(models.Model):
>> title = models.CharField(max_length=100, unique=True)
>> def __unicode__(self):
>> return self.title
>>
>> class Category(models.Model):
>> client = models.ForeignKey(Client, to_field='title')
>> title = models.CharField(max_length=200, unique=True)
>> def __unicode__(self):
>> return self.title
>>
>> class Subcategory(models.Model):
>> client = models.ForeignKey(Client, to_field='title')
>> category = models.ForeignKey(Category, to_field='title')
>> title = models.CharField(max_length=200, unique=True)
>> def __unicode__(self):
>> return self.title
>>
>> class Project(models.Model):
>> client = models.ForeignKey(Client, to_field='title')
>> category = models.ForeignKey(Category, to_field='title')
>> subcategory = models.ForeignKey(Subcategory, to_field='title')
>> title = models.CharField(max_length=200, unique=True)
>> def __unicode__(self):
>> return self.title
>>
>> class Type(models.Model):
>> client = models.ForeignKey(Client, to_field='title')
>> category = models.ForeignKey(Category, to_field='title')
>> subcategory = models.ForeignKey(Subcategory, to_field='title')
>> project = models.ForeignKey(Project, to_field='title')
>> title = models.CharField(max_length=200, unique=True)
>> def __unicode__(self):
>> return self.title
>>
>> class Page(models.Model):
>> client = models.ForeignKey(Client, to_field='title')
>> category = models.ForeignKey(Category, to_field='title')
>> subcategory = models.ForeignKey(Subcategory, to_field='title')
>> project = models.ForeignKey(Project, to_field='title')
>> type = models.ForeignKey(Type, to_field='title')
>> pageurl = models.CharField

View.py v models.py

2012-09-26 Thread Lachlan Musicman
Hi

I was doing some work on a view last night and realised that the code
could go into either views.py or as a method on the model.

Do people have internal guidelines about when they make something a
method on a model rather than a view function? Is there any functional
difference apart from the obvious "a model method can be called from
an object"?

Cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: View.py v models.py

2012-09-26 Thread Lachlan Musicman
On Thu, Sep 27, 2012 at 10:59 AM, Javier Guerra Giraldez
 wrote:
> On Wed, Sep 26, 2012 at 5:50 PM, Lachlan Musicman  wrote:
>> Do people have internal guidelines about when they make something a
>> method on a model rather than a view function?
>
> if it's not a presentation thing, it probably goes in the model
>
> even some presentation things go there, like the __unicode__ method;
> but nothing that assumes HTML

The more I think about it, the more it makes sense to put it in the
model - then the Generic views can be used instead of having a long
and ugly views.py filled with methods

Hmmm

L.


>
> --
> Javier
>
> --
> 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.
>



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



conditional model validation

2012-09-27 Thread Lachlan Musicman
Hola,

I'm searching without much luck and can't see the answer in the docs.

Am wanting to override the is_valid() method on a model (I think
that's what I want).

Basically, I have a choices field, and if one of those choices is
selected, then I want a description field to be not blank/not the
empty string. If it's the other two choices, I want the description
field to be blank/empty string.

First, I override is_valid() as a model method?

Second, how do I return a false from is_valid()?

ie, this is a rough up of what I'm looking for - what goes in place of
return FALSE/TRUE?

def is_valid(self):

if enrolment.mark == 'W': #student has withdrawn from course
-if enrolment.withdrawal_reason == '': #must have reason
--return FALSE
elif enrolment.withdrawal.reason != "": #ie, since enrolment.mark
isn't 'W', confirm that the enrolment.reason is ""
-return FALSE
else:
-return TRUE

Cheers
L.
-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



last changed by User

2012-09-27 Thread Lachlan Musicman
Hola,

I wanted to display the user that last changed a model instance.

It's hard to search for because the username/email-as-login makes up the
majority of the search results.

Despite this, I've found a couple of pages, with this being the most like
what I want:

https://code.djangoproject.com/wiki/CookBookNewformsAdminAndUser

I like this solution - simple and clean, easy to implement.

My only reservation is that I was under the impression that this
information was already being kept and that putting a

user = ForeignKey("User")

in each model that I want to track is doubling up on the data I'm keeping?

Cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: last changed by User

2012-09-27 Thread Lachlan Musicman
On Friday, September 28, 2012, Lachlan Musicman wrote:

>
> I wanted to display the user that last changed a model instance.
>
> Despite this, I've found a couple of pages, with this being the most like
> what I want:
>
> https://code.djangoproject.com/wiki/CookBookNewformsAdminAndUser
>
> I like this solution - simple and clean, easy to implement.
>
> My only reservation is that I was under the impression that this
> information was already being kept and that putting a
>
> user = ForeignKey("User")
>
> in each model that I want to track is doubling up on the data I'm keeping?
>

To clarify - I can see the last ten actions I've taken when I'm logged into
the admin interface - is this info permanent and easy to access and display
on the model DetailView?

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: i am getting ConfigParser.NoSectionError: No section: 'database' plz help

2012-09-27 Thread Lachlan Musicman
On Fri, Sep 28, 2012 at 4:05 PM, Navnath Gadakh  wrote:
> ConfigParser.NoSectionError: No section: 'database'

Off the top of my head, I would suggest you have nothing in the
section DATABASES in your settings.py

Does your settings.py have something that looks like:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.DBNAME',
'NAME': 'xe',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': '',
'PORT': '',
}
}

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: i am getting ConfigParser.NoSectionError: No section: 'database' plz help

2012-09-27 Thread Lachlan Musicman
On Fri, Sep 28, 2012 at 4:15 PM, Lachlan Musicman  wrote:
> On Fri, Sep 28, 2012 at 4:05 PM, Navnath Gadakh  
> wrote:
>> ConfigParser.NoSectionError: No section: 'database'

Although a quick google of the phrase is showing up lots of
mysql-python hits - is python-mysqldb (for ubuntu, YMMV) installed
correctly on your system?

Cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: conditional model validation

2012-09-28 Thread Lachlan Musicman
On Friday, September 28, 2012, Babatunde Akinyanmi wrote:

> Let me try to assist. A forms is_valid method causes 3 types of
> cleaning methods to be run. Based on that, I'm sure you really don't
> need to override it.
>
>
Yes, I've just discoverde the ValidationError e part of the docs :|



> I really don't understand what you mean by "I want the description
> field to be not blank/not the empty string" so maybe I could have been
> of more help but I'm sure a solution to your problem would be to
> override either the form's clean_fieldname or clean methods.
>

ie,
if e.mark = W, e.descr must be >"" # it can be anything from "a" to
"pregnant" to "killed" to "this is not an empty string" or " this is not a
blank string"
else e.descr == "" #this is a blank or empty string





> Check: https://docs.djangoproject.com/en/dev/ref/forms/validation/
> which is a link to the documentation on form validation
>


cheers - since I am using the admin forms, I was hoping I could add it to
the model, but is ok if I need to rewrite the forms

cheers
L.


> On 9/28/12, Lachlan Musicman > wrote:
> > Hola,
> >
> > I'm searching without much luck and can't see the answer in the docs.
> >
> > Am wanting to override the is_valid() method on a model (I think
> > that's what I want).
> >
> > Basically, I have a choices field, and if one of those choices is
> > selected, then I want a description field to be not blank/not the
> > empty string. If it's the other two choices, I want the description
> > field to be blank/empty string.
> >
> > First, I override is_valid() as a model method?
> >
> > Second, how do I return a false from is_valid()?
> >
> > ie, this is a rough up of what I'm looking for - what goes in place of
> > return FALSE/TRUE?
> >
> > def is_valid(self):
> >
> > if enrolment.mark == 'W': #student has withdrawn from course
> > -if enrolment.withdrawal_reason == '': #must have reason
> > --return FALSE
> > elif enrolment.withdrawal.reason != "": #ie, since enrolment.mark
> > isn't 'W', confirm that the enrolment.reason is ""
> > -return FALSE
> > else:
> > -return TRUE
> >
> > Cheers
> > L.
> > --
> > ...we look at the present day through a rear-view mirror. This is
> > something Marshall McLuhan said back in the Sixties, when the world
> > was in the grip of authentic-seeming future narratives. He said, “We
> > look at the present through a rear-view mirror. We march backwards
> > into the future.”
> >
> > http://www.warrenellis.com/?p=14314
> >
> > --
> > 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.
> >
> >
>
> --
> Sent from my mobile device
>
> --
> 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.
>
>

-- 
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Like a Formset but not...

2012-10-03 Thread Lachlan Musicman
Hi,

I am looking for a way to do something similar to a formset, but
slightly different.

I have a list of students in a class (class as a school subject, not
class in programming) with attendance record objects having a FK to
both student and class, as well as two fields with choices lists
relating to attendance (present, absent | reasons for absence)

What I want is an uneditable list of students on a page, and next to
each student a RadioSelect widget for each of the fields relating to
attendance.

I successfully created a page with formsets listing all the attendance
records for a class, and excluded the unnecessary fields - but this
means that the student FK field is rendered as a drop down list of all
students - ie, it's editable. (as a side note, each record in the
formset is not followed by a line break, making the output ugly. I
didn't expect that)

This is not the desired outcome.

I have thought about going pure views.py - creating a list of students
from the class object and cobbling together some html to add the two
attendance fields, potentially unlinked to the model itself, to render
the page via a table/divs, but am concerned about how stupidly complex
it could become for quite a simple problem, when taking into account
differing numbers of students, matching student names with the radio
buttons selected and using get_or_create()...

Is this via views.py the best method, or am I missing something obvious?

Cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Inlines defined before use?

2012-10-03 Thread Lachlan Musicman
Hola,

I'm finding that if my inlines aren't defined before use in the
admin.py, I'm getting the following errors:

inlines=('MyModelInline',)
"issubclass() arg 1 must be a class" Errors

inlines=(MyModelInline,)
"name 'MyModelInline' is not defined"

This is a minor issue, easily solved by putting the inlines at the top
of the admin.py

Is this meant to be how it works?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Managers, Queryset, inheritance and polymorphism

2012-10-08 Thread Lachlan Musicman
On Sat, Oct 6, 2012 at 3:14 AM, Amirouche  wrote:
> Héllo,
>
> I got a problem with manager, some of you may already know it, I try my best
> to like them, if anyone can explain me the purpose of their existence I will
> be so much grateful :)
>
> Like I said, I try my best but:
>
> 0) Documentation references «default_manager», but I don't find it in the
> code, is it a documentation bug ?

I don't think it's a bug, but I agree there is some mental gymnastics
that needs to happen. I remember the  same.

The default manager is usually the "objects" in MyModel.objects.all().

But if you add new managers, the TOP manager is the default manager -
as a result, a lot of people add the

objects = models.Manager()

to the top of their list of managers, followed by the self defined managers.

> 0bis) What is the purpose of «_default_manager» and «_base_manager» ?

Riffing from the top of my head, (ie, I don't know exact motivations,
but am pretty sure it's) that managers are integral to data use.

ie, the base_manager is the class in the code that gives us the
managers, and the default manager is the standard out of the box
manager. Base exists so that managers can be extended.

Look at your code. How often do you use MyModel.objects.all() or
MyModel.objects.filter(x=y) or anything like that at all? That's all
Managers. This is why we need managers - so that we don't have to
write SELECT * FROM TABLENAME WHERE X=Y (or whatever the SQL is)

I wish I could answer the rest of your questions, but I'm only new to
Django too :)
cheers
L.


> 1) What is the purpose of «Manager.db», it's not used in Manager class, so I
> don't think it's used anywhere else
>
> 2) Polymorphism
>
> Is there anyone that can debug two level and more of inheritance in
> Django-Polymorphic
> I think this a revision of Django Polymorphic that works with that problem,
> anyone knows the revision hash ?
> Do you know any other application that does polymorphism the way I need it
> (with several level of inheritance) ?
>
> If they are answers to question 2, I might no need the answer to the
> following questions, I still would like to know.
>
> I have the following models, manager and querysets
> https://gist.github.com/3826531
>
> According to the code of  Manager in manager.py, I just need to override
> «get_query_set», but here is what I get as results, the bug is in the second
> line:
>
>> In [14]: PolymorphicQuerySet(Entry)
>> Out[14]: [, , , ,
>> , , ]
>> In [15]: Entry.objects.all()
>> Out[15]: []
>
>
> What am I doing wrong ?
>
> Thanks,
>
>
> Amirouche
>
> --
> 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/-/G20heNLwu6IJ.
> 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.



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Inlines defined before use?

2012-10-08 Thread Lachlan Musicman
On Sat, Oct 6, 2012 at 4:29 AM, Bill Freeman  wrote:
> There are a few special cases in which Django works hard to allow you
> to specify a string that will be looked up later.  And you can use
> names in function and method definitions that will be defined by the
> time the function is called.  But python does not, in general, support
> forward references.

Ok, thanks for the info. I still struggle to seperate python and
django in my mind - I know they aren't the same thing, but I realise
that some things should be thought of as python actions/procedures,
and others are django-wranglings.

Cheers
L.


>
> On Wed, Oct 3, 2012 at 5:58 PM, Lachlan Musicman  wrote:
>> Hola,
>>
>> I'm finding that if my inlines aren't defined before use in the
>> admin.py, I'm getting the following errors:
>>
>> inlines=('MyModelInline',)
>> "issubclass() arg 1 must be a class" Errors
>>
>> inlines=(MyModelInline,)
>> "name 'MyModelInline' is not defined"
>>
>> This is a minor issue, easily solved by putting the inlines at the top
>> of the admin.py
>>
>> Is this meant to be how it works?
>>
>> cheers
>> L.
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>>
>> --
>> 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.
>



-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Django testing strategy

2012-10-09 Thread Lachlan Musicman
This has been a very interesting thread - out of interest, does anyone
have a preference for one of factory-boy or django-dynamic-fixture and
why?

They look similarly up to date and useful, but I've no idea how to
differentiate them.

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: perfectionists... motto doesn't fit

2012-10-13 Thread Lachlan Musicman
On Sat, Oct 13, 2012 at 12:39 PM, Russell Keith-Magee
 wrote:
>> Russell (and Jacob),
>>
>> I really appreciate the way you moderate the forum.

I was thinking exactly this when I read Russell's first response. This
is an excellently run community. Thankyou for your work

cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



Overriding admin save event

2012-10-15 Thread Lachlan Musicman
Hola,

I wanted to override the save event in the admin so that users were
redirected to a different page.

I found this page describing how to do it:
http://www.ibm.com/developerworks/opensource/library/os-django-admin/index.html#listing10

It recommends two methods and describes one:

"There are two ways to change the behavior of the Save button: You can
override admin.ModelAdmin.response_add, which is responsible for the
actual redirection after a save, or you can override
admin.ModelAdmin.change_view. The latter is somewhat simple"

This post is from 2009. Are these two methods still the best way to go
about this, and rather than which is simple, which is considered "more
django/more pythonic/more canonical"?

cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Overriding admin save event

2012-10-15 Thread Lachlan Musicman
On Tue, Oct 16, 2012 at 12:52 PM, Lachlan Musicman  wrote:
> Hola,
>
> I wanted to override the save event in the admin so that users were
> redirected to a different page.

Of course, further reading has turned up signals. Is this the current
recommended method?

eg:

from django.db.models.signals import pre_save
from django.dispatch import receiver
from myapp.models import MyModel

@receiver(post_save)
def redirect(sender, **kwargs):
HttpResponseRedirect('/my/prefered/url/')

?

Cheers
L.

-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
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.



  1   2   3   4   5   >