Re: GROUP BY and ORDER BY using the ORM

2010-07-05 Thread MikeHowarth
Thanks Euan, some great info there.

I'll have a dig through the docs for F objects, I wasn't even aware of
them so thanks for point me in that direction!

On 5 July, 10:35, "euan.godd...@googlemail.com"
 wrote:
> I'd only use extra as a total last resort as it often results in poor
> portability between DB backends. That said if you're only ever going
> to stick to one you might not care.
>
> Django introduced F objects in 1.1. The documentation is not great and
> my experiments with it haven't been a massive success, but you might
> be able to achieve something like this with F (if you want to filter
> on being older than a certain number of days).
>
> Euan
>
> On Jul 5, 10:05 am, MikeHowarth  wrote:
>
> > You're right I sniped the date_time field when pasting in the model
> > after leaving out some extranous detail. Doh!
>
> > Ordering by date_time mean't I had duplicates despite grouping by
> > site. Like you say printing out the query may actually help me
> > understand what is going on under the hood.
>
> > After posting the message, I did a bit more reading I actually used
> > annotate(last_date=MAX('date_time')) which seems to work reasonably
> > well and give me the sort of result I was looking for. Again I'll
> > print the sql for this and see whats going on.
>
> > Extending the use case a bit further however what I'd really like to
> > do is determine how many days have passed since 'last date' and filter
> > the objects further. It sort of seems as though I'm getting to the
> > edge of what the ORM is capable of.
>
> > From doing a quick bit of reading it either seems like I'll have to
> > use the extra() clause or perhaps look at using a property bound to a
> > method however at this point you're outside the scope of the ORM.
>
> > Any ideas on how I can best acheive this?
>
> > I'm trying to stay away from using a foreach and looping over a
> > potentially large number of records and doing this filtering at the DB/
> > ORM level.
>
> > Thanks in advance.
>
> > On 5 July, 07:32, "euan.godd...@googlemail.com"
>
> >  wrote:
> > > Erm. You don't seem to have specified what to order by. In this case,
> > > surely you want ... .order_by('date_time') However, this field doesn't
> > > seem to appear in your models.
>
> > > One thing I've found handy for debugging Django's ORM to SQL is
> > > something which I don't think is documented in django docs at all
> > > (although I maybe wrong about that) is doing:
>
> > > print qs.query
>
> > > Where qs is your queryset. It will output the SQL Django sends to the
> > > DB backend.
>
> > > Euan
>
> > > On 3 July, 15:03, MikeHowarth  wrote:
>
> > > > Hi all
>
> > > > Just coming back to Django after a long time away, and struggling to
> > > > get my head around what should be a trivial concept using the ORM.
>
> > > > Essentially I want to do acheive the following SQL:
>
> > > > SELECT * FROM publisher_history
> > > > INNER JOIN publisher_publisher ON publisher_publisher.id =
> > > > publisher_history.publisher_id
> > > > GROUP BY publisher_id ORDER BY date_time DESC;
>
> > > > My models look like this:
>
> > > > class Publisher(models.Model):
> > > >         name = models.CharField(max_length=100, blank=False)
>
> > > > class History(models.Model):
> > > >         publisher = models.ForeignKey(Publisher, blank=False)
>
> > > > I've been trying to use object values, but I'm getting duplicate
> > > > publishers. Code looks like this:
>
> > > > results = History.objects.values('publisher').distinct()
>
> > > > If I run:
>
> > > > results = History.objects.values('publisher').distinct().order_by()
>
> > > > I don't get duplicates but I don't get the results returned in the
> > > > order I expect either.
>
> > > > Any help would be greatly appreciated, I've stared at this for a while
> > > > now.

-- 
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: GROUP BY and ORDER BY using the ORM

2010-07-05 Thread MikeHowarth
You're right I sniped the date_time field when pasting in the model
after leaving out some extranous detail. Doh!

Ordering by date_time mean't I had duplicates despite grouping by
site. Like you say printing out the query may actually help me
understand what is going on under the hood.

After posting the message, I did a bit more reading I actually used
annotate(last_date=MAX('date_time')) which seems to work reasonably
well and give me the sort of result I was looking for. Again I'll
print the sql for this and see whats going on.

Extending the use case a bit further however what I'd really like to
do is determine how many days have passed since 'last date' and filter
the objects further. It sort of seems as though I'm getting to the
edge of what the ORM is capable of.

>From doing a quick bit of reading it either seems like I'll have to
use the extra() clause or perhaps look at using a property bound to a
method however at this point you're outside the scope of the ORM.

Any ideas on how I can best acheive this?

I'm trying to stay away from using a foreach and looping over a
potentially large number of records and doing this filtering at the DB/
ORM level.

Thanks in advance.

On 5 July, 07:32, "euan.godd...@googlemail.com"
 wrote:
> Erm. You don't seem to have specified what to order by. In this case,
> surely you want ... .order_by('date_time') However, this field doesn't
> seem to appear in your models.
>
> One thing I've found handy for debugging Django's ORM to SQL is
> something which I don't think is documented in django docs at all
> (although I maybe wrong about that) is doing:
>
> print qs.query
>
> Where qs is your queryset. It will output the SQL Django sends to the
> DB backend.
>
> Euan
>
> On 3 July, 15:03, MikeHowarth  wrote:
>
> > Hi all
>
> > Just coming back to Django after a long time away, and struggling to
> > get my head around what should be a trivial concept using the ORM.
>
> > Essentially I want to do acheive the following SQL:
>
> > SELECT * FROM publisher_history
> > INNER JOIN publisher_publisher ON publisher_publisher.id =
> > publisher_history.publisher_id
> > GROUP BY publisher_id ORDER BY date_time DESC;
>
> > My models look like this:
>
> > class Publisher(models.Model):
> >         name = models.CharField(max_length=100, blank=False)
>
> > class History(models.Model):
> >         publisher = models.ForeignKey(Publisher, blank=False)
>
> > I've been trying to use object values, but I'm getting duplicate
> > publishers. Code looks like this:
>
> > results = History.objects.values('publisher').distinct()
>
> > If I run:
>
> > results = History.objects.values('publisher').distinct().order_by()
>
> > I don't get duplicates but I don't get the results returned in the
> > order I expect either.
>
> > Any help would be greatly appreciated, I've stared at this for a while
> > now.

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



GROUP BY and ORDER BY using the ORM

2010-07-03 Thread MikeHowarth
Hi all

Just coming back to Django after a long time away, and struggling to
get my head around what should be a trivial concept using the ORM.

Essentially I want to do acheive the following SQL:

SELECT * FROM publisher_history
INNER JOIN publisher_publisher ON publisher_publisher.id =
publisher_history.publisher_id
GROUP BY publisher_id ORDER BY date_time DESC;

My models look like this:

class Publisher(models.Model):
name = models.CharField(max_length=100, blank=False)

class History(models.Model):
publisher = models.ForeignKey(Publisher, blank=False)

I've been trying to use object values, but I'm getting duplicate
publishers. Code looks like this:

results = History.objects.values('publisher').distinct()

If I run:

results = History.objects.values('publisher').distinct().order_by()

I don't get duplicates but I don't get the results returned in the
order I expect either.

Any help would be greatly appreciated, I've stared at this for a while
now.

-- 
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: Filtering ManyToManyField

2008-09-11 Thread MikeHowarth

Anyone?

I'm really struggling with this.

As stated in my first post running the code creates a recursive loop.

Had a bit of a hack around with things, but can't figure anything
obvious out.

On Sep 11, 10:58 am, MikeHowarth <[EMAIL PROTECTED]> wrote:
> The model I'm using is very similar to that of Satchmo's
>
> Model basically looks like this:
>
> class Product(models.Model):
> name = models.CharField(_("Full Name"), max_length=255, blank=False,
> slug = models.SlugField(_("Slug Name"), blank=True,
> related_items = models.ManyToManyField('self', blank=True, null=True,
> verbose_name=_('Related Items'), related_name='related_products')
>
> David Reynolds wrote:
> > On 11 Sep 2008, at 10:06 am, MikeHowarth wrote:
>
> > > Could anyone clarify what I need to do be doing to acheive the desired
> > > filtering?
>
> > Can we see your model too?
>
> > Although, I note satchmo do a similar thing:
>
> >http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/
> > product/models.py#L458
>
> > --
> > David Reynolds
> > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Filtering ManyToManyField

2008-09-11 Thread MikeHowarth

The model I'm using is very similar to that of Satchmo's

Model basically looks like this:

class Product(models.Model):
name = models.CharField(_("Full Name"), max_length=255, blank=False,
slug = models.SlugField(_("Slug Name"), blank=True,
related_items = models.ManyToManyField('self', blank=True, null=True,
verbose_name=_('Related Items'), related_name='related_products')


David Reynolds wrote:
> On 11 Sep 2008, at 10:06 am, MikeHowarth wrote:
>
> > Could anyone clarify what I need to do be doing to acheive the desired
> > filtering?
>
> Can we see your model too?
>
> Although, I note satchmo do a similar thing:
>
> http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/
> product/models.py#L458
>
> --
> David Reynolds
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Filtering ManyToManyField

2008-09-11 Thread MikeHowarth

I was wondering if anyone could help me.

I currently have a Product model which has a many to many association
linked back to itself for related items.

When returning the related items, I want to filter out any which are
not currently flagged as active.

Initially I thought about doing something like this:

def _get_related_items(self):
self.related_items.exclude(active=0)

related_items = property(_get_related_items)

However I've managed to create a recursive query.

Could anyone clarify what I need to do be doing to acheive the desired
filtering?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Forms across multiple pages?

2008-09-06 Thread MikeHowarth

Can't seem to find anything of relevance in the docs, so wondering if
someone could help me.

Basically I want to put an email signup form in the footer of my site,
which I can display errors/success message in place.

Other than using Ajax to post this info in the background is there a
way in Django to actually have a form on a page which has an action
to another page and return error messages/success message back to the
previous one i.e hooking in to global error variables or similar?

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



Re: Standalone script + get_absolute_url with urlresolvers

2008-07-14 Thread MikeHowarth

Think I may have found the issue.

My .pth file was pointing to an old directory which didn't have the
relevant module.

For anyone wondering, its permissable not to have a views.py providing
you have the __init__.py and models.py

On Jul 14, 10:28 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
> Yeah. I did think that.
>
> As far as I'm aware there aren't any errors in any of the views,
> however the views.py file for scripts it is an empty file. I'm
> guessing this is the problem in itself.
>
> Is it syntactically correct to have a views.py which is empty but
> exists? I'm not really sure of the process Django will use to validate
> the view.
>
> I've also pasted the stack trace to Dpaste:http://dpaste.com/64942/
>
> On Jul 14, 8:35 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
> > Hi Mike,
>
> > > I'm running a standalone script outside of the web server to do some
> > > maintainence tasks.
>
> > > In particular I need to return the absolute url from one of my models,
> > > however when I call the get_absolute_url() method, I'm getting a
> > > ViewDoesNotExist exception raised. A view exists however upon further
> > > investigation I've found that this line of code is causing me some
> > > real problems:
>
> > > return urlresolvers.reverse('satchmo_product', kwargs={'product_slug':
> > > self.slug})
>
> > > Basically it appears that Django is concatenating the view path or
> > > similar, so instead of either searching in:
> > > satchmo.shop.views or satchmo.scripts.views
>
> > > Its actually searching in satcho.shop.views.satchmo.scripts.views
>
> > > Anyone got any idea how I could overide Django to tell it where to
> > > search for the view or similar?
>
> > Do you have a stack trace you can DPaste?
>
> > The urlresolvers.reverse function throws an exception if *any* of your
> > URLs anywhere in the project have a bad view and not necessarily the
> > one you are trying to reverse map. So, check that you don't have any
> > URL mappings with undefined view functions (or views with syntax
> > errors).
>
> > Since 'satchmo_product' is a named URL mapping, Django should resolve
> > that to the right Satchmo view directly without going through any
> > searches.
>
> > -Rajesh D
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Standalone script + get_absolute_url with urlresolvers

2008-07-14 Thread MikeHowarth

Yeah. I did think that.

As far as I'm aware there aren't any errors in any of the views,
however the views.py file for scripts it is an empty file. I'm
guessing this is the problem in itself.

Is it syntactically correct to have a views.py which is empty but
exists? I'm not really sure of the process Django will use to validate
the view.

I've also pasted the stack trace to Dpaste: http://dpaste.com/64942/

On Jul 14, 8:35 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> Hi Mike,
>
>
>
>
>
> > I'm running a standalone script outside of the web server to do some
> > maintainence tasks.
>
> > In particular I need to return the absolute url from one of my models,
> > however when I call the get_absolute_url() method, I'm getting a
> > ViewDoesNotExist exception raised. A view exists however upon further
> > investigation I've found that this line of code is causing me some
> > real problems:
>
> > return urlresolvers.reverse('satchmo_product', kwargs={'product_slug':
> > self.slug})
>
> > Basically it appears that Django is concatenating the view path or
> > similar, so instead of either searching in:
> > satchmo.shop.views or satchmo.scripts.views
>
> > Its actually searching in satcho.shop.views.satchmo.scripts.views
>
> > Anyone got any idea how I could overide Django to tell it where to
> > search for the view or similar?
>
> Do you have a stack trace you can DPaste?
>
> The urlresolvers.reverse function throws an exception if *any* of your
> URLs anywhere in the project have a bad view and not necessarily the
> one you are trying to reverse map. So, check that you don't have any
> URL mappings with undefined view functions (or views with syntax
> errors).
>
> Since 'satchmo_product' is a named URL mapping, Django should resolve
> that to the right Satchmo view directly without going through any
> searches.
>
> -Rajesh D
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Standalone script + get_absolute_url with urlresolvers

2008-07-14 Thread MikeHowarth

I was wondering whether anyone can help me with a problem I'm having.

I'm running a standalone script outside of the web server to do some
maintainence tasks.

In particular I need to return the absolute url from one of my models,
however when I call the get_absolute_url() method, I'm getting a
ViewDoesNotExist exception raised. A view exists however upon further
investigation I've found that this line of code is causing me some
real problems:

return urlresolvers.reverse('satchmo_product', kwargs={'product_slug':
self.slug})

Basically it appears that Django is concatenating the view path or
similar, so instead of either searching in:
satchmo.shop.views or satchmo.scripts.views

Its actually searching in satcho.shop.views.satchmo.scripts.views

Anyone got any idea how I could overide Django to tell it where to
search for the view or similar?




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Access urls in template tags?

2007-11-29 Thread MikeHowarth

Basically I'm looking to expand a sub navigation dependent upon
whether the category belongs to the selected hierachy.

Basically I was thinking of doing something along the lines:

url = 'parent/child'
url_bits = url.split('/')

if cat.slug == url[1]:
   #build parent nav - don't recurse
else:
   #build parent/child nav - hence recurse

The logic should be fairly straightforward, however what I'm stumped
by is how I would access the url within a template tag given I won't
already have a request object.

Is there a simple way to do this within the template tag or would I
need to create a context processor and would this be available within
the templatetag or only within the template itself?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MS SQLServer syncdb problem

2007-11-02 Thread MikeHowarth

As far as I'm aware SQL Server isn't supported, there was a project
going a while ago but I think it has lost momentum.

On Nov 2, 11:36 am, lopes <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm trying to make a syncdb and I've got the following message on
> creating "auth_user" table, i've already installed pywin32-210.win32-
> py2.5.exe and adodbapi.
>
> Any ideas?
>
> >python manage.py syncdb
>
> Creating table auth_message
> Creating table auth_group
> Creating table auth_user
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File "C:\Python25\lib\site-packages\django\core\management.py", line
> 1672, in execute_manager
> execute_from_command_line(action_mapping, argv)
>   File "C:\Python25\lib\site-packages\django\core\management.py", line
> 1571, in execute_from_command_line
> action_mapping[action](int(options.verbosity),
> options.interactive)
>   File "C:\Python25\lib\site-packages\django\core\management.py", line
> 534, in syncdb
> cursor.execute(statement)
>   File "C:\Python25\lib\site-packages\django\db\backends\util.py",
> line 12, in execute
> return self.cursor.execute(sql, params)
>   File "build\bdist.win32\egg\adodbapi\adodbapi.py", line 713, in
> execute
>   File "build\bdist.win32\egg\adodbapi\adodbapi.py", line 664, in
> _executeHelper
>   File "build\bdist.win32\egg\adodbapi\adodbapi.py", line 474, in
> _raiseCursorError
>   File "build\bdist.win32\egg\adodbapi\adodbapi.py", line 60, in
> standardErrorHandler
> adodbapi.adodbapi.DatabaseError:
> --ADODBAPI
> Traceback (most recent call last):
>File "build\bdist.win32\egg\adodbapi\adodbapi.py", line 650, in
> _executeHelper
> adoRetVal=self.cmd.Execute()
>File "", line 3, in Execute
>File "c:\python25\lib\site-packages\pywin32-210-py2.5-win32.egg
> \win32com\client\dynamic.py", line 258, in _ApplyTypes_
> result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
> retType, argTypes) + args)
>  com_error: (-2147352567, 'Ocorreu uma excep\xe7\xe3o.', (0,
> 'Microsoft OLE DB Provider for SQL Server', "Line 1: Incorrect syntax
> near 'DEFERRABLE'.", None, 0,
>  -2147217900), None)
> -- on command: "ALTER TABLE [auth_message] ADD CONSTRAINT
> user_id_refs_id_650f49a6 FOREIGN KEY ([user_id]) REFERENCES
> [auth_user] ([id]) DEFERRABLE INITIALLY DE
> FERRED;"
> -- with parameters: ()


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form_for_instance + user profile

2007-09-13 Thread MikeHowarth

Well I thought I had this working but it turns out it was previous
form I had set up manually.

At the moment I'm getting no form returned at all, from reading the
documentation I'm struggling to see what I'm doing wrong.

My UserProfile model is sat in eshop.shop.models, I'm referencing this
in settings.py like so:

#Use the shop profile model
AUTH_PROFILE_MODULE = 'shop.UserProfile'

Model looks like this:

class UserProfile(models.Model):

title = models.CharField(maxlength=10)
user = models.ForeignKey(User, unique=True)

View looks like this:

user = get_object_or_404(User, id=12)
user_profile = user.get_profile()

UserForm = form_for_instance(user_profile)

if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/url/on_success/')
else:
form = UserForm()

return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))

Can anyone spot the glaringly obvious mistake I'm struggling to see??


On Sep 12, 8:28 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
> Yep all working now!
>
> On Sep 12, 8:11 pm, RajeshD <[EMAIL PROTECTED]> wrote:
>
> > > Basic example:
>
> > > user = User.objects.get(id=1)
> > > user_profile = user.get_profile()
>
> > This should work if you have settings.AUTH_PROFILE_MODULE pointing to
> > your UserProfile model. 
> > See:http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-13 Thread MikeHowarth

Look at form_for_instance in newforms:

http://www.djangoproject.com/documentation/newforms/



On Sep 13, 9:08 am, "Peter Melvyn" <[EMAIL PROTECTED]> wrote:
> On 9/11/07, Ole Laursen <[EMAIL PROTECTED]> wrote:
>
> > You can also use the initial parameter when instantiating the form:
>
> And how to solve situation when you've processed posted data and in
> the next step you need to redisplay the same form with some values
> reset to initial values?
>
> Peter


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form_for_instance + user profile

2007-09-12 Thread MikeHowarth

Yep all working now!

On Sep 12, 8:11 pm, RajeshD <[EMAIL PROTECTED]> wrote:
> > Basic example:
>
> > user = User.objects.get(id=1)
> > user_profile = user.get_profile()
>
> This should work if you have settings.AUTH_PROFILE_MODULE pointing to
> your UserProfile model. 
> See:http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Master Page Code

2007-09-12 Thread MikeHowarth

Have a look at template inheritance

http://www.djangoproject.com/documentation/templates/#template-inheritance

This may give you more of any idea of how to structure your main
template.


[EMAIL PROTECTED] wrote:
> I'm a web developer and I'm developing my first application using
> Django.  I'm very impressed with the MVC concept in Django.  I'm
> addressing this group for some advice on how to organize my code for
> this web application.
>
> Basically, my application will have the typical master page that will
> contain things like: page title, website logo, top banner, user id and
> login status, main menu, the typical 3 column layout with 'ad blocks'
> on each side, content in the center column and finally a footer with
> copyright information.
>
> I'm not sure at this point what would be the best place to put the
> Python code that takes care of creating the context for the elements
> contained in this master template.  Should I subclass a master page?
>
> Any advice on this subject would be greately appreciated.
>
> Thanks,
> Carlos Perez


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



form_for_instance + user profile

2007-09-12 Thread MikeHowarth

I've had a read through the docs and have created a UserProfile object
with a ForeignKey to Djangos User object.

What I want to be able to do is load the UserProfile so this can then
be edits.

I tried this last night (admittedly not very hard) and didn't seem to
have any joy.

Basic example:

user = User.objects.get(id=1)
user_profile = user.get_profile()
user_form = form_for_instance(user_profile, fields=('a field I want to
filter'))

Should this work or should I be loading the user profile like so:

user = User.objects.get(id=1)
user_profile = UserProfile(user)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Temporary access to link in django

2007-09-12 Thread MikeHowarth

I think you may be complicating things unnecesarily by not creating a
user.

Why not look at creating a temporary user group, and maybe adding an
additional check at login if this user is a temporary user, they
cannot login 1 month after the date created of the user?

On Sep 12, 7:50 am, Przemek Gawronski <[EMAIL PROTECTED]>
wrote:
> Hi, I want to give a temporary access to link to a visitor but I don't
> want to create an user account for him but give access only to him. In
> general the scenario is to look more/less like this:
>
> 1 - visitor fills a form with some data, including an email field and a
> password,
> 2 - data from the form is saved for processing,
> 3 - email is sent to this visitor with a generated link, so he can view
> his data (and possibly follow up info) any time he wishes but has to
> confirm the password when entering the link,
> 4 - if there is any new info for him, a email will be send to notify,
> 5 - after a month the record is deleted and the link doesn't work
> any more and there should be no trace of it.
>
> How could I do that avoiding the creation and later deletion of a new
> user for each visitor?
>
> Thanks for suggestions and help
>
> Przemek
> --
> AIKIDO TANREN DOJO  -   Poland - Warsaw - Mokotow - Ursynow - Natolin
> info:  http://tanren.pl/  phone:+4850151   email:[EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Login issues

2007-09-11 Thread MikeHowarth

Russ

Thanks for the reply Russ, I totally missed this.

I did wonder whether this was because I was using the email-auth
backend.

I'll implement your suggestion and see what happens.

On Sep 11, 1:50 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 9/10/07, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi guys
>
> > Was wondering if anyone knew of any bugs within the user
> > authentication system associated to setting the backend attribute?
>
> Not that I'm aware of - and certainly not with the default
> authentication backend.
>
> > Basically looking at the traceback the user object expects a attribute
> > 'backend' to be set within however this doesn not seem to be set.
>
> My guess here would be to check that the user object that is produced
> in the clean method by the authentication is the same object that is
> used in the login method. The code you defines the user as a class
> attribute, not an instance attribute, but you are using it as an
> instance attribute in the login method. Depending on how you are
> instantiating and using this form, you may be getting some wierd
> behaviour.
>
> Yours,
> Russ Magee %-)


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



Re: first naive question for a new fresh Django user

2007-09-11 Thread MikeHowarth

To be honest I'm not really sure the use of Ajax in printing a piece
of text from a field is that necessary. This could easily be acheived
using good old javascript.

On Sep 11, 3:25 pm, vincent garonne <[EMAIL PROTECTED]> wrote:
> *  would like 
>
> vincent garonne a écrit :
>
>
>
> > Hi,
>
> > I would to do the same than this example:
>
> >http://www.hackorama.com/ajax/
>
> > Vince
>
> > MikeHowarth a écrit :
>
> >> I'm not entirely sure I follow your request.
>
> >> However using Ajax in Django is a fairly simple affair:http://www.b-
> >> list.org/weblog/2006/jul/02/django-and-ajax/
>
> >> On Sep 11, 3:11 pm, garonne <[EMAIL PROTECTED]> wrote:
>
> >>> Hello,
>
> >>> I 've started playing with Django which seems very well for what i
> >>> need but i still can figure out how to implement a very simple ajax
> >>> example:
>
> >>> I would like to have a form with a  textarea and after pressing the
> >>> button, i wish to see the form and the text print below. For some
> >>> reason i'm not able to keep both on the same page. I put my code
> >>> below.
>
> >>>> cat views.py
>
> >>> from django.http  import HttpResponse
> >>> from django.shortcuts import render_to_response
>
> >>> from django   import newforms as forms
>
> >>> from django.contrib.admin.views.decorators import
> >>> staff_member_required
>
> >>> class Form(forms.Form):
> >>> Entry  = forms.CharField(max_length=100)
>
> >>> def index(request):
> >>> if request.method == 'POST':
> >>> form = Form(request.POST)
> >>> if  form['Entry'].data  == "" or form['Entry'].data is
> >>> None :
> >>> Entry  = " No entry"
> >>> else:
> >>> Entry  = form['Entry'].data
> >>> return render_to_response('index.html', {'Entry': Entry})
> >>> else:
> >>> form = Form()
> >>> return render_to_response('index.html', {'form': form})
>
> >>>> cat index.html
>
> >>>  >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> >>> http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> >>> 
> >>> 
> >>> Testr
> >>> 
>
> >>> 
>
> >>> 
> >>> 
> >>> {{ form.as_table }}
> >>> 
> >>> 
> >>> 
>
> >>> {% if Entry %}
> >>> 
> >>> Entry : {{Entry}}
>
> >>> 
> >>> {% endif %}
>
> >>> 
>
> >>> I've found a way which is to resent a form variable to index HTML but
> >>> i think this is not the right thing to do. I would like to fill my
> >>> page in a incremental way.  I think this is a trivial recipe...
>
> >>> Thanks for your help,
> >>> Vincent.
>
> --
> ---<[EMAIL PROTECTED]>
> Vincent Garonne  http://cern.ch/vincent.garonne
> CERN PH, CH-1211, Geneva 23, Switzerland
> Tel. +41 22 76 71181Fax. +41 22 76 78350
> --=-


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: first naive question for a new fresh Django user

2007-09-11 Thread MikeHowarth

I'm not entirely sure I follow your request.

However using Ajax in Django is a fairly simple affair:http://www.b-
list.org/weblog/2006/jul/02/django-and-ajax/



On Sep 11, 3:11 pm, garonne <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I 've started playing with Django which seems very well for what i
> need but i still can figure out how to implement a very simple ajax
> example:
>
> I would like to have a form with a  textarea and after pressing the
> button, i wish to see the form and the text print below. For some
> reason i'm not able to keep both on the same page. I put my code
> below.
>
> > cat views.py
>
> from django.http  import HttpResponse
> from django.shortcuts import render_to_response
>
> from django   import newforms as forms
>
> from django.contrib.admin.views.decorators import
> staff_member_required
>
> class Form(forms.Form):
> Entry  = forms.CharField(max_length=100)
>
> def index(request):
> if request.method == 'POST':
> form = Form(request.POST)
> if  form['Entry'].data  == "" or form['Entry'].data is
> None :
> Entry  = " No entry"
> else:
> Entry  = form['Entry'].data
> return render_to_response('index.html', {'Entry': Entry})
> else:
> form = Form()
> return render_to_response('index.html', {'form': form})
>
> > cat index.html
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> 
> 
> Testr
> 
>
> 
>
> 
> 
> {{ form.as_table }}
> 
> 
> 
>
> {% if Entry %}
> 
> Entry : {{Entry}}
>
> 
> {% endif %}
>
> 
>
> I've found a way which is to resent a form variable to index HTML but
> i think this is not the right thing to do. I would like to fill my
> page in a incremental way.  I think this is a trivial recipe...
>
> Thanks for your help,
> Vincent.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Populating a form

2007-09-11 Thread MikeHowarth

You'll need to load an instance of the model, which will pre-populate
the data:

http://www.djangoproject.com/documentation/newforms/#form-for-instance

On Sep 11, 7:15 am, AniNair <[EMAIL PROTECTED]> wrote:
> Hi...
>I am trying to learn python and django.  Can someone please tell me
> how to populate some fields in a form? I want to have certain values
> present in CharField  or Textfield . (Eg:For editing a profile: the
> data previously entered needs to be present in the resp fields...)
> Please help. Thank you


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Email as username in django auth framework

2007-09-10 Thread MikeHowarth

I'm using this snippet which works fine.

In order to get this working, I generate a random string as the
username on creation and created a unique index on the email address
field.

I guess it goes a little against the grain given you're patching the
db however I feel email address fields should be unique to ensure you
don't have multiple users registered with the same address.

HTH

On Sep 10, 3:15 pm, novice <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am using the django auth and liking it, but I would like to make the
> username to be an email field. I can do it easily by changing the user
> model in the auth, but is there any way of accomplishing this without
> changing the user model? I came across this 
> snippetwww.djangosnippets.org/snippets/74/
> which is somehow related to what I need but this one is telling how to
> use the username or the email to login, users still have to register
> with a user name that is not an email.
>
> Thanks in advance!
> Oumer


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Login issues

2007-09-10 Thread MikeHowarth

Anyone?

On Sep 9, 5:47 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
> Hi guys
>
> Was wondering if anyone knew of any bugs within the user
> authentication system associated to setting the backend attribute?
>
> Basically looking at the traceback the user object expects a attribute
> 'backend' to be set within however this doesn not seem to be set.
>
> Traceback:
>
> Traceback (most recent call last):
> File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> get_response
>   77. response = callback(request, *callback_args, **callback_kwargs)
> File "D:\Web Dev\Test\eshop\..\eshop\login\views.py" in login
>   10. if loginform.login(request):
> File "D:\Web Dev\Test\eshop\..\eshop\login\forms.py" in login
>   56. login(request, self.user)
> File "C:\Python25\lib\site-packages\django\contrib\auth\__init__.py"
> in login
>   53. request.session[BACKEND_SESSION_KEY] = user.backend
>
>   AttributeError at /login/
>   'User' object has no attribute 'backend'
>
> Forms.py
>
> class LoginForm(forms.Form):
>
> username = forms.CharField(label=_('username'))
> password = forms.CharField(label=_('password'))
> user = None   # allow access to user object
>
> def clean(self):
>
> # only do further checks if the rest was valid
> if self._errors: return
>
> from django.contrib.auth import login, authenticate
>
> user = authenticate(username=self.data['username'],
> password=self.data['password'])
>
> if user is not None:
> if user.is_active:
> self.user = user
> else:
> raise forms.ValidationError(ugettext(
> 'This account is currently inactive. Please
> contact '
> 'the administrator if you believe this to be
> in error.'))
> else:
> raise forms.ValidationError(ugettext(
> 'The username and password you specified are not
> valid.'))
>
> def login(self, request):
>
> from django.contrib.auth import login
>
> if self.is_valid():
> login(request, self.user)
> return True
> return False


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can u help me how to configure MOD_PYTHON am new one to django

2007-09-10 Thread MikeHowarth

You'd place the configuration code with the httpd.conf file

Once done restart Apache

On Sep 10, 7:36 am, Damodhar <[EMAIL PROTECTED]> wrote:
> hi
> I,am new one to django,
>
> I am very intrst to learn Django, so i install python latest verson,
> and try to install daango latest verson but it want;s's to
> configure .. mod_python module , can u help me
>
> am using WINDOWS XP SYSTEM  now am working in PHP MYSQL USING XAMPLITE
> (APACHE +PHP + MYSQL Package)
>
> i read the documentation for mod_python intallation but i cant able to
> get ckear idea
>
> wher do iwant to configure path apache\bin i found  APXS file ...I
> wwant to configure(write inside the apxs file ) or  apache\conf\
> httpd.config file... where do i want to write a  configuration code ,
> can u pls give me the details and code and were exactly write it
> please give me the step by step.. to run django .
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: entering sane dates in admin

2007-09-10 Thread MikeHowarth

Sure have a look at the DATE_FORMAT within settings.

I think that should do what you're after.

On Sep 8, 8:29 am, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
> hi,
> is there any quick way of entering sane dates in admin - that is d/m/
> y and not y/m/d?
> --
>
> regards
> kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/web/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newbie (Before I get started)

2007-09-10 Thread MikeHowarth

I've been working in Django for all of about 4 weeks and I'm
absolutely loving it. Within that time I've written my first project,
something which I probably would never have acheived in another
language (I'd still be stuck reading the book!)

To give you a little on my background, I've programmed PHP for around
8 years, having previously worked with ASP, Perl and looked at
both .NET and Rails in passing. Recently I've been using Python for
some backend scripting and came across Django so I thought I'd do a
little more reading around

>From what I saw in that bit of reading I was pretty much blown away by
the ethos of the project and I've been hooked ever since.

Yep, there are less resources available for Django at the moment
however the documentation is more than sufficient (it just take a
little reading), there is a book soon to be published and available
at: http://www.djangobook.com

On top of this the group is both very helpful and very active and
active with the people who are actually developing the framework which
surely counts for something!

The admin system is extendable to meet your requirements, I see the
admin as more of a bonus than a hinderance.

Ruby more forgiving than Python, can't really comment as I'm not
overly familiar with Ruby's syntax.


On Sep 10, 7:16 am, tmb <[EMAIL PROTECTED]> wrote:
> I've spent a few days Googling and searching this group for some
> guidance on a few newbie issues. I apologize in advance if these
> things have already been covered to death.
>
> I am basically trying to decide where to put my focus in the next
> project or two: Rails or Django. Haha, yeah I know... :) My question
> is not necessarily which is better, that would be dumb, but which
> might be better suited for a n00b.
>
> Here's what really makes me lean toward Django.
>
> 1.) Perfomance, ease of deployment and documentation.
> 2.) Love python syntax.
> 3.) I like the pragmatic vibe of the community and no nonsense
> approach. I'm a little tired of 'baked right in' and all other
> buzzworthy lingo.
> 4.) Google API avaible in Python.
>
> The only thing that doesn't make this a clear cut decision are a few
> issues:
>
> 1.) Rails has more books, reference, code examples, etc.
> 2.) I've read and been told it's easier to create a cutom admin
> (something about sessions). As much as I love Django auto-admin, it
> will not suit my next project.
> 3.)>> Ruby may be more forgiving than Python???
>
> Thanks for any light that can be shone my way. I apologize in advance
> if I have missed any previous threads covering these issues.
>
> -TMB


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Login issues

2007-09-09 Thread MikeHowarth

Hi guys

Was wondering if anyone knew of any bugs within the user
authentication system associated to setting the backend attribute?

Basically looking at the traceback the user object expects a attribute
'backend' to be set within however this doesn not seem to be set.

Traceback:

Traceback (most recent call last):
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "D:\Web Dev\Test\eshop\..\eshop\login\views.py" in login
  10. if loginform.login(request):
File "D:\Web Dev\Test\eshop\..\eshop\login\forms.py" in login
  56. login(request, self.user)
File "C:\Python25\lib\site-packages\django\contrib\auth\__init__.py"
in login
  53. request.session[BACKEND_SESSION_KEY] = user.backend

  AttributeError at /login/
  'User' object has no attribute 'backend'

Forms.py

class LoginForm(forms.Form):

username = forms.CharField(label=_('username'))
password = forms.CharField(label=_('password'))
user = None   # allow access to user object

def clean(self):

# only do further checks if the rest was valid
if self._errors: return

from django.contrib.auth import login, authenticate

user = authenticate(username=self.data['username'],
password=self.data['password'])

if user is not None:
if user.is_active:
self.user = user
else:
raise forms.ValidationError(ugettext(
'This account is currently inactive. Please
contact '
'the administrator if you believe this to be
in error.'))
else:
raise forms.ValidationError(ugettext(
'The username and password you specified are not
valid.'))

def login(self, request):

from django.contrib.auth import login

if self.is_valid():
login(request, self.user)
return True
return False


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Hierarchical menus

2007-09-06 Thread MikeHowarth

Chris

Thanks for the plug!

Reading through that code makes it much clearer and gives me a great
example to follow. I've been thinking about looking at satchmo you
could just have another convert!

cheers

Mike

On Sep 5, 9:21 pm, "Chris Moffitt" <[EMAIL PROTECTED]> wrote:
> I've used satchmo before as an example but here it is again.
>
> Here is the model that describes the 
> category-http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/prod...
>
> Here is the template to display the 
> menu-http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/temp...
>
> This template tag does all of the hard 
> work-http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop...
>
> Hope this helps.
>
> -Chris


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Hierarchical menus

2007-09-05 Thread MikeHowarth

I was wondering whether anyone can help me, I'm absolutely stumped
where to start creating a hierarchical menu in Django. I've scoured
Google and don't seem to be able to find anything to get me started.

Basically I'm looking to create a simple list based menu like so:

> Home
 > Category 1
  > Range 1
  > Range 2
 > Category 2
 > Category 3

To explain I currently have my models like so:

class Category(models.Model):
id = models.AutoField('id', primary_key=True)
name = models.CharField(maxlength=50)

class Range(models.Model):
id = models.AutoField('id', primary_key=True)
category = models.ForeignKey(Category)
name = models.CharField(maxlength=50)

Initially I'd thought about using the select_related syntax along
these lines:
Range.objects.all().select_related()

However I'm not sure that is going give me the granularity I won't be
able to determine the depth of the navigation or whether this is the
parent of the range selected.

Any help would be greatly appreciated!


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: localflavor - UKPostcodeField

2007-08-21 Thread MikeHowarth

Thats a very valid point Malcolm and something I'll implement!

On Aug 21, 12:22 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2007-08-21 at 02:20 -0700, MikeHowarth wrote:
> > So really I'd be better off using:
>
> > from django.contrib.localflavor.uk import forms
>
> If, in the same file, you also do "import newforms as forms", things are
> going to go pear-shaped pretty quickly, so be careful.
>
> My gut reaction, if I'm importing "extra" stuff like this and it's using
> a common name, is to immediately, defensively alias it to something like
> uk_forms so that even three months from now, I don't spend forever
> trying to debug why "forms" doesn't contain what I expect it to.
>
> Malcolm
>
> --
> A clear conscience is usually the sign of a bad 
> memory.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: localflavor - UKPostcodeField

2007-08-21 Thread MikeHowarth

So really I'd be better off using:

from django.contrib.localflavor.uk import forms

On Aug 21, 9:35 am, Collin Grady <[EMAIL PROTECTED]> wrote:
> The same question applies though :)
>
> You didn't import the "forms" bit, you imported the field directly, so
> you should just be using it as UKPostcodeField :)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: localflavor - UKPostcodeField

2007-08-21 Thread MikeHowarth

Sorry that was a typo on my part Colin

Should have read:

forms.UKPostcodeField()

Think its time for a coffee!


On Aug 21, 9:19 am, Collin Grady <[EMAIL PROTECTED]> wrote:
> You're importing UKPostcodeField - so why are you trying to use
> models.UKPostcodeField ? :)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: index page

2007-08-21 Thread MikeHowarth

It really depends on how complicated you want to make it.

However using generic views would easily suffice, just set up a
dictionary of the objects you need to pass in. Something like:
django.views.generic.simple.direct_to_template would do the job.


On Aug 21, 9:12 am, Rufman <[EMAIL PROTECTED]> wrote:
> hi
>
> does anyone have a good idea how i could make an index page that
> combines different apps. e.g. the results of a poll is shown as well
> as a news feed next to it.
>
> thanks
>
> stephane rufer


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



localflavor - UKPostcodeField

2007-08-21 Thread MikeHowarth

Hi

I came across localflavors and would like to use the UKPostcodeField
for post code validation. However when I try to import this I'm
getting ViewDoesNotExist errors.

Within my forms.py I'm importing like so:

from django.contrib.localflavor.uk.forms import UKPostcodeField

I'm then referencing this within the class like so:

models.UKPostcodeField()

>From here I've also checking within the Django installation on my
python path to ensure that this exists. But no joy!


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attribute Error

2007-08-20 Thread MikeHowarth

Guys

I spent quite a while yesterday reading through the newforms section
of the docs, and thought I'd taken everything in.

As a python novice, I wrote a test script and couldn't replicate the
error, so was beginning to wonder whether I was cracking up! After
reading Malcolm's (comprehensive) response, it does make alot more
sense and I feel to have a better understanding of how the newforms
library hinges together.

I've got to say as someone new to django I'm really impressed at the
level of support you guys have got going on.

On Aug 20, 6:54 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2007-08-19 at 14:30 -0700, MikeHowarth wrote:
> > I'll take a look at that.
>
> > Even commenting that line out and attempting to access self.title I'm
> > still getting an attribute error thrown: 'Register' object has no
> > attribute 'title'
>
> Doug Ballanc has explained how you should be writing your save() method.
> I thought I might just add something about why what you're doing doesn't
> seem to work, despite looking like perfectly valid Python code.
>
> The newforms Form class has a specialised __new__ method, which is what
> is responsible for attaching attributes to the object you get back from
> calling Form(). In the default case (i.e. pretty much always), what this
> method does is *not* creating attributes for anything that is a
> newforms.fields.Field subclass. Rather, those fields are put into an
> attribute called "base_fields" (which is copied to an attribute called
> "fields" in __init__).
>
> All this metaclass stuff happens in DeclarativeFieldsMetaclass in
> newforms.forms. Replacing the metaclass with something elase to populate
> the base_fields leaves open some interesting possibilities about how to
> initialise form classes for those with imagination.
>
> This might look very strange and, in a way, it is unusual. When I was
> wondering, early on in newforms life, why this was done (I think my
> initial mental question was "what was he smoking?"), I realised there
> isn't a completely natural thing to store in those attributes. Do they
> hold the normalized, cleaned data? The original value? Both, depending
> upon whether clean has been called? If the attribute is None, does that
> mean we don't have that value? We haven't set it yet? Or that the form's
> normalized value is None (possible for some fields)? How would you know
> which fields had errors in them and what would prevent you accidentally
> accessing those attributes and treating the values as real values?
>
> To some extent, it reduces confusion by not having attributes at all for
> fields. Instead, you initialise a form with the raw, submitted data.
> Then you access "cleaned_data" or is_valid() or "errors" whenever you
> like and the raw data is cleaned and normalized (where possible) and
> sent to two dictionaries: Form.cleaned_data and Form.errors.
>
> So, whilst what you were attempting might seem logical on one level,
> hopefully I've explained why it could, in many cases, be more confusing
> and error-prone than convenient. So the design uses a slightly different
> approach from providing access to the form data and errors.
>
> Best wishes,
> Malcolm
>
> --
> Borrow from a pessimist - they don't expect it 
> back.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Attribute Error

2007-08-19 Thread MikeHowarth

I'll take a look at that.

Even commenting that line out and attempting to access self.title I'm
still getting an attribute error thrown: 'Register' object has no
attribute 'title'

On Aug 19, 10:22 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> As a first guess I'm not sure that user = User is doing what you would
> want.  I think instead you want to instantiate a new User object.  All
> you are doing right now is creating an alias user for User.
>
> On Aug 19, 3:16 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
> > Hi I was wondering whether anyone can help me out.
>
> > I'm currently creating a form to register users, what I'm finding is
> > that when I then attempt to save the user within the Register:save
> > method I'm getting an attribute error when trying to access the title
> > attribute. I've tried referencing both title, and self.title to no
> > avail.
>
> > Can anyone advise me on where I'm going wrong with this?
>
> > class Register(forms.Form):
>
> > def __init__(self, data=None, request=None, *args, **kwargs):
> > if request is None:
> > raise TypeError("Keyword argument 'request' must be 
> > supplied")
> > super(Register, self).__init__(data, *args, **kwargs)
> > self.request = request
>
> > #personal information
> > title = forms.ChoiceField(choices=titlechoice)
>
> > def save(self):
>
> > #set up the objects we are going to populate
> > user = User
> > user.title = self.title


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Attribute Error

2007-08-19 Thread MikeHowarth

Hi I was wondering whether anyone can help me out.

I'm currently creating a form to register users, what I'm finding is
that when I then attempt to save the user within the Register:save
method I'm getting an attribute error when trying to access the title
attribute. I've tried referencing both title, and self.title to no
avail.

Can anyone advise me on where I'm going wrong with this?

class Register(forms.Form):

def __init__(self, data=None, request=None, *args, **kwargs):
if request is None:
raise TypeError("Keyword argument 'request' must be 
supplied")
super(Register, self).__init__(data, *args, **kwargs)
self.request = request


#personal information
title = forms.ChoiceField(choices=titlechoice)

def save(self):

#set up the objects we are going to populate
user = User
user.title = self.title


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Site Map template required?

2007-08-17 Thread MikeHowarth

Will do, thanks for your patience Malcolm

On Aug 17, 5:52 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-08-16 at 11:03 -0700, MikeHowarth wrote:
> > Malcolm
>
> > Thanks for your comments, indeed changing to use the sitemap view,
> > then returns a template does not exist error.
>
> > If I create a sitemap.xml file in my templates directory I then bypass
> > this. What I'm struggling with is that the documentation suggests that
> > the feed is automatically generated.
>
> It should be using the sitemaps.xml template from
> django/contrib/sitemaps/templates/. You might want to double-check that
> you have followed all the steps in the Installation section of the
> sitemaps documentation. If that is correctly set up, then check that
> django/contrib/sitemaps/templates/ exists and contains two files
> (sitemap_index.xml and sitemap.xml).
>
> Regards,
> Malcolm
>
> --
> Depression is merely anger without 
> enthusiasm.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-cart integration?

2007-08-16 Thread MikeHowarth

Thats absolutely it. Validated and no errors found. Great stuff.

I was sure I'd searched for Teacher and couldn't find anything.

Thanks again for your help.

On Aug 16, 8:32 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> If I remember this correctly, Talk is the item being sold in the
> store, and it has a foreignkey relationship with Teacher... so that's
> where you're getting your error.
>
> You don't need Talks (unless that's what you're selling).
> Where it says from eshop.talks.models import Talk, you need to change
> that to import the thing you're going to sell.
>
> On Aug 16, 1:12 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
> > Importing other bits of code is still fairly new to me, I only started
> > looking at django last week.
>
> > I basically took the files out of subversion and created a dir
> > structure like so:
>
> > /eshop/shop
> > /eshop/cart  <- django cart installed here
> > /eshop/talks <- additional django cart files
>
> > Within my settings.py my installed apps looks like this:
>
> > INSTALLED_APPS = (
> > 'django.contrib.auth',
> > 'django.contrib.contenttypes',
> > 'django.contrib.sessions',
> > 'django.contrib.sites',
> > 'django.contrib.admin',
> > 'django.contrib.flatpages',
> > 'django.contrib.sitemaps',
> > 'eshop.shop',
> > 'eshop.cart',
> > 'eshop.talks',
> > )
>
> > I've snipped the contents to keep it a readable length. All imports
> > happen at the top of the page so hopefully this should give you an
> > idea of whats going on.
>
> > Models follow:
>
> > eshop/shop/models.py
>
> > from django.db import models
> > from django.contrib.sitemaps import Sitemap
>
> > import datetime
>
> > #more model logic snipped contents
>
> > eshop/cart/models.py
>
> > from eshop.talks.models import Talk
>
> > PRICE=12 # All units have a price of $12 for now.
>
> > class Item:
>
> > #snipped contents
>
> > eshop/talks/models.py
>
> > from django.contrib.sites.models import Site
> > from django.db import models
> > from django.conf import settings
>
> > class Talk(models.Model):
>
> >  #snipped contents
>
> > On Aug 16, 5:02 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> > > I've got it set up, but it's not plug and play... it's tied fairly
> > > closely to a model you don't have.
> > > It's trying to import Teacher from that model. You need to import your
> > > stuff from your models.
>
> > > On Aug 16, 3:02 am, "Jon Atkinson" <[EMAIL PROTECTED]> wrote:
>
> > > > On 8/15/07, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
> > > > > Does anyone have experience of integrating django-cart in to an app?
>
> > > > > I've tried adding this to my project, however soon as I use runserver
> > > > > I get issues with the models:
>
> > > > > name 'Teacher' is not defined
>
> > > > > Anyone any idea?
>
> > > > Could you paste the output of ./manage.py validate, and your models.py
> > > > file for each of your apps? It sounds like you're just missing an
> > > > import statement somewhere.
>
> > > > --Jon


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-cart integration?

2007-08-16 Thread MikeHowarth

Importing other bits of code is still fairly new to me, I only started
looking at django last week.

I basically took the files out of subversion and created a dir
structure like so:

/eshop/shop
/eshop/cart  <- django cart installed here
/eshop/talks <- additional django cart files

Within my settings.py my installed apps looks like this:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.flatpages',
'django.contrib.sitemaps',
'eshop.shop',
'eshop.cart',
'eshop.talks',
)

I've snipped the contents to keep it a readable length. All imports
happen at the top of the page so hopefully this should give you an
idea of whats going on.

Models follow:

eshop/shop/models.py

from django.db import models
from django.contrib.sitemaps import Sitemap

import datetime

#more model logic snipped contents

eshop/cart/models.py

from eshop.talks.models import Talk

PRICE=12 # All units have a price of $12 for now.

class Item:

#snipped contents



eshop/talks/models.py

from django.contrib.sites.models import Site
from django.db import models
from django.conf import settings

class Talk(models.Model):

 #snipped contents





On Aug 16, 5:02 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I've got it set up, but it's not plug and play... it's tied fairly
> closely to a model you don't have.
> It's trying to import Teacher from that model. You need to import your
> stuff from your models.
>
> On Aug 16, 3:02 am, "Jon Atkinson" <[EMAIL PROTECTED]> wrote:
>
> > On 8/15/07, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
> > > Does anyone have experience of integrating django-cart in to an app?
>
> > > I've tried adding this to my project, however soon as I use runserver
> > > I get issues with the models:
>
> > > name 'Teacher' is not defined
>
> > > Anyone any idea?
>
> > Could you paste the output of ./manage.py validate, and your models.py
> > file for each of your apps? It sounds like you're just missing an
> > import statement somewhere.
>
> > --Jon


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Site Map template required?

2007-08-16 Thread MikeHowarth

Malcolm

Thanks for your comments, indeed changing to use the sitemap view,
then returns a template does not exist error.

If I create a sitemap.xml file in my templates directory I then bypass
this. What I'm struggling with is that the documentation suggests that
the feed is automatically generated.

Is it then down to me to mark up a template and output the objects and
if so whats the naming of the object thats passed? This is something
that seems to have been skipped totally in the docs.

Regards

Mike

On Aug 16, 5:47 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2007-08-15 at 12:52 -0700, MikeHowarth wrote:
> > I've read through the site maps documentation, and seem to have
> > followed it to the letter, however I've getting a NoReverseMatch at /
> > sitemap.xml error.
>
> Where are you getting this error from? It's not really enough to report
> the error without the location. The traceback will tell you the
> location. The only place I can see it might be occurring is in
> contrib/sitemaps/views.py and that suggests you URL setup isn't correct:
>
> [...]
>
> > urlpatterns = patterns('',
> > (r'^sitemap.xml$', 'django.contrib.sitemaps.views.index',
> > {'sitemaps': sitemaps}),
> > )
>
> The docs I'm looking at (in the subversion source) say to add a line
> that says
>
> (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap',
> {'sitemaps': sitemaps})
>
> if you are creating one file or, if you are using the index version, you
> need to have two URLconf entries, the second one looking something like
> (again, from the docs):
>
> (r'^sitemap-(?P.+).xml$',
> 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})
>
> In both cases, the import thing is that
> django.contrib.sitemaps.views.sitemap appears in your URL conf. This si
> not the case with the example you've given.
>
> Regards,
> Malcolm
>
> --
> Depression is merely anger without 
> enthusiasm.http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django-cart integration?

2007-08-15 Thread MikeHowarth

Does anyone have experience of integrating django-cart in to an app?

I've tried adding this to my project, however soon as I use runserver
I get issues with the models:

name 'Teacher' is not defined

Anyone any idea?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Site Map template required?

2007-08-15 Thread MikeHowarth

I've read through the site maps documentation, and seem to have
followed it to the letter, however I've getting a NoReverseMatch at /
sitemap.xml error.

urls.py looks like this:

from django.conf.urls.defaults import *
from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
from eshop.shop.models import Category,Product

product_dict = {
'queryset': Product.objects.all(),
'template_name': 'product.html',
'slug_field': 'slug_field',
}

sitemaps = {
'product': GenericSitemap(product_dict, priority=0.6),
}

urlpatterns = patterns('',
(r'^sitemap.xml$', 'django.contrib.sitemaps.views.index',
{'sitemaps': sitemaps}),
)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic View Pagination

2007-08-14 Thread MikeHowarth

I'd read that as well Collin and obviously totally forgotten about.

I'll give that a whirl!

On Aug 13, 11:54 pm, Collin Grady <[EMAIL PROTECTED]> wrote:
> As the documentation for object_list says, it will append _list to
> template_object_name, so you should actually be checking
> "products_list" based on your line there :)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Generic View Pagination

2007-08-13 Thread MikeHowarth

>From reading the documentation on generic views, I don't seem to be
making much head way. Basically I'm looking to create a paginated page
displaying all products within a specific category.

Within my urls.py I call the category view within my app:

(r'^category/(?P\d+)/$', 'eshop.shop.views.category'),

My category view then looks like this:

from django.views.generic.list_detail import object_list
from eshop.shop.models import Category, Product

def category(request, category_id):

category = Category.objects.filter(id=category_id)
products = Product.objects.filter(category=category_id)

category_count = category.count()
product_count = products.count()

return object_list(request, queryset=products,
template_object_name='products', paginate_by=1,
template_name='category.html', extra_context={'category':category,
'category_count':category_count, 'product_count':product_count,
'category_id':category_id})

Within the template when I conditionally check for products or
categories nothing is executed, despite returning a product count of
4, and a category count of 1.

Am I missing something glaringly obvious, its driving me mad!


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SlugField not prepopulating?

2007-08-13 Thread MikeHowarth

Thanks for such a quick reply Richard.

Yep think it was a combination of not displaying and also not having
an additional comma at the end of the prepopulate_from tuple.



On Aug 13, 10:26 pm, RichardH <[EMAIL PROTECTED]> wrote:
> Mike, welcome to Django.
> The prepopulate_from relies on Javascript in the admin pages, so only
> works in the site admin interface. However you have also set
> editable=False, so it will not be seen in the admin pages anyway.>From the 
> Model Reference documentation:
>
> "SlugField ... Accepts an extra option, prepopulate_from, which is a
> list of fields from which to auto-populate the slug, via JavaScript,
> in the object's admin form"
> What you need is the slugify function from
> django.template.defaultfilters in your save function to set the slug.
> or there is an alternative at:http://www.djangosnippets.org/snippets/168/
>
> Richard
>
> On Aug 13, 9:25 pm, MikeHowarth <[EMAIL PROTECTED]> wrote:
>
> > Hi
>
> > I was wondering whether anyone could help me, I just starting out with
> > Django and am attempting to write a simple web app. Ideally I'd like
> > to use a slug field populated based on the name of my product.
>
> > However the slug field is not being populated, my model looks like
> > this:
>
> > class Product(models.Model):
>
> > name = models.CharField(maxlength=255)
> > category = models.ForeignKey(Category)
> > slug =
> > models.SlugField(prepopulate_from=("name",),unique=True,editable=False)
> > description = models.TextField()
> > size = models.CharField(maxlength=50)
> > price = models.FloatField(max_digits=5, decimal_places=2)
> > delivery = models.ForeignKey(Delivery)
> > in_stock = models.BooleanField()
> > display = models.BooleanField()
> > pub_date = models.DateTimeField(editable=False)
>
> > def __str__(self):
> > return self.name
>
> > def save(self):
> > if not self.id:
> > self.pub_date = datetime.datetime.now()
> > super(Product, self).save()
>
> > Any help would be greatly appreciated


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



SlugField not prepopulating?

2007-08-13 Thread MikeHowarth

Hi

I was wondering whether anyone could help me, I just starting out with
Django and am attempting to write a simple web app. Ideally I'd like
to use a slug field populated based on the name of my product.

However the slug field is not being populated, my model looks like
this:

class Product(models.Model):

name = models.CharField(maxlength=255)
category = models.ForeignKey(Category)
slug =
models.SlugField(prepopulate_from=("name",),unique=True,editable=False)
description = models.TextField()
size = models.CharField(maxlength=50)
price = models.FloatField(max_digits=5, decimal_places=2)
delivery = models.ForeignKey(Delivery)
in_stock = models.BooleanField()
display = models.BooleanField()
pub_date = models.DateTimeField(editable=False)

def __str__(self):
return self.name

def save(self):
if not self.id:
self.pub_date = datetime.datetime.now()
super(Product, self).save()

Any help would be greatly appreciated


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---