Re: Customised admin saving

2009-07-11 Thread Friðrik Már Jónsson

Daniele Procida wrote:
> I think this means that I need to add a routine to my admin.py so that
> when the user hits Save, it will also manually assemble the information
> and save it for the affected models. 
>
> Is that correct? If so, what is doing this called, so I can look it up
> in the documentation?
>   
It seems you want to run code at save-time with access to the user's 
selection for a certain field.

You can do this in the admin with ``ModelAdmin.save_model(...)``[1], but 
if you don't need access to the `request` object or direct access to the 
form being submitted you're better off doing something that will apply 
to all ``save()``s regardless of the view that displays them, like a 
``pre_save`` or ``post_save`` signal.

Regards,
Friðrik Már

[1] 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model
[2] 
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save

--~--~-~--~~~---~--~~
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: Make three columns without violating DRY

2009-07-09 Thread Friðrik Már Jónsson

Javier Guerra wrote:
>
> write a column template:
> ---
> {% [f]or article in col_articles %}
>{{article}}
>  {% endfor %}
> ---
>
> and call it three times, with a different col_articles

That's still breaking the DRY principle. :)  Alex got it right.

Regards,
Friðrik Már
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: creating user directories upon account activation

2009-07-09 Thread Friðrik Már Jónsson

Hi,


>if SHA1_RE.search(activation_key):
>try:
>profile = self.get(activation_key=activation_key)
>except self.model.DoesNotExist:
>return False
>if not profile.activation_key_expired():
>user = profile.user
>user.is_active = True
>user.save()
>profile.activation_key = self.model.ACTIVATED
>profile.save()
>try:
>import os
>os.mkdir(MEDIA_ROOT + '/listings/' + user)
>except IOError:
>   print "could not create folder."
>return user
>return False


For one, I'm a tad befuzzled that you don't get an unexpected indent  
error where your `print` statement is.

Kindly hand over the value of `user_directory_path` and nobody will  
get hurt.

   user_directory_path = os.path.join(MEDIA_ROOT, 'listings',  
user.username)
   os.mkdir(user_directory_path)
   print user_directory_path

> I'm attempting to use a try except to catch any error but I don't  
> think I'm using it correctly.

If you don't want an exception when an IOError is thrown (e.g. can't  
write to that location), but instead want "could not create folder."  
printed on your runserver console, you are using it correctly.

Regards,
Friðrik Már
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django way to design this model

2009-07-09 Thread Friðrik Már Jónsson

Hi Divesh,

> I have this model that I want to design on Django. I have already
> created the mysql side of it, and the mysql database is ready. Also, i
> have loaded mysqldb and i think it works.

It sounds like you've created something with MySQL and imported it to  
a database that's used by Django.  This is not the same as creating  
actual models in your `models.py` file, which is required if you want  
to make use of Django's querying methods.

> (Species 1 & 2). And then you write a view, that will do the searching
> according parameters (Tolerance, pagination, species 1&2)
>
> So I have to create something like the website above on Django. Was
> just wondering if there was any easy way of doing this.. I don't fully
> understand Django yet, and am not sure if  have to make a form or
> what? I'm really confused.
>
> Basically what I want to do is create that type of a site, with only
> one species, and then have it such that when you click the radio
> button next to one species, it shows you what that species corresponds
> to in the mysql database.

You need to take this one step at a time.  You seem to be mixing model  
creation (defining the data structure) with writing views and  
templates (the radio button, pagination, criteria).

  1. Design the model[1] to the specification that is your current  
MySQL schema.
  2. Fill the model with some test data[2].
  3. Use the shell to try to retrieve the objects[3] according to the  
criteria you would get from your user through the view.
  4. Move the queries you've created to a view that renders results to  
a template.  If you start doing this by accepting GET parameters and  
displaying the search results through the template, you can get the  
query functionality working and test it by changing the URL before  
creating the actual search form.
  5. Create the search form, probably using `django.forms`[4] and use  
a `ChoiceField(widget=RadioSelect, choices=...)`[5] to present the  
options to users.

If this is all sounding like nonsese to you, it probably means you  
should spend some time reading up on Django's excellent documentation,  
and if you haven't already, finish the tutorial.

Regards,
Friðrik Már

  [1] http://docs.djangoproject.com/en/dev/topics/db/models/
  [2] http://docs.djangoproject.com/en/dev/topics/db/queries/#creating-objects
  [3] http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-objects
  [4] http://docs.djangoproject.com/en/dev/topics/forms/
  [5] 
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.RadioSelect
--~--~-~--~~~---~--~~
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: ImportError: No module named urls

2009-07-09 Thread Friðrik Már Jónsson

Hey!

A full traceback could be helpful.

A lot of time when you've got really strange import errors they have  
something to do with circular imports. Did you change any imports  
right before or after the upgrade?

Regards,
Friðrik Már

On Jul 9, 2009, at 3:25 PM, huw_at1 wrote:

>
> Hi all,
>
> I have just been moving my website to a production server and am
> having some difficulty getting it working. I have upgraded the Django
> from 1.0 on my development server to 1.1 on the production server.
> When I try to access the admin pages I get an Internal Server Error
> and a message in the apache logs stating "Import Error: No module
> named urls". I have tried running the shell and importing the urls
> module from within and outside of the local directory both of which
> work fine.
>
> I'm guessing it's either some value in my settings file or something
> is non-backwards compatible going from 1.0 to 1.1 but I am a bit
> clueless as to what atm. Any suggestions would be most welcome.
>
> Many thanks
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django reporting

2009-07-08 Thread Friðrik Már Jónsson

Hi ankit,

ankit wrote:
> What is django reporting is anybody has some idea ?

I think you should have put some more time into crafting your question.

If you're referring to the django-reporting module (in which case a  
Google search should have sufficed), you can read up on it online[2].

Regards,
Friðrik Már

P.S. You should read How To Ask Questions The Smart Way[2].  Please  
don't be offended, this is the friendliest hint; it's a good and  
insightful read about asking good questions that everyone needs at one  
time or another.

[1] http://code.google.com/p/django-reporting/
[2] http://catb.org/esr/faqs/smart-questions.html
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---