Re: Re: Singleton model instance

2006-12-07 Thread Phil Powell

Thanks for the input guys.  I'm kind of approaching this from a client
perspective, so was fishing around for the simplest use case from an
inexperienced admin user's point of view.

The suggestions of using a Page and "chunk" schema makes perfect
sense, and a quick Google threw up a good example[1].

However, I was kind of missing a trick, as Django's admin provides
exactly what I need in the form of user permissions - all I need to do
is set up a single intance for a given page model, with the fields
defined.  Then it's just a matter of changing permissions to only
allow client users to edit that instance.

Thanks for your help guys - all food for thought.

-Phil

[1] http://www.carthage.edu/webdev/?p=15

On 05/12/06, Jeff Forcier <[EMAIL PROTECTED]> wrote:
>
> As James and Fredrik have implied, I believe the proper solution here
> is to abstract things enough so that you *can* map the concept to a
> relational database; in this case, assuming that every 'Page' has an
> identifier, a 'Title' and, perhaps, multiple 'Sections' (each with an
> identifier and text), you make a Page model with (unique) Name and
> Title attributes, and then a Section or PageSection or etc, model, with
> Name and Text fields and a ForeignKey to Page.
>
> Then your homepage is a Page whose Name is "homepage" and whose Title
> is the page title, then with a few Sections: one named "introduction"
> with the intro text, one named "footer" with footer text, etc.
>
> Finally, you'd probably want to make a templatetag that operates on
> these models, so you can do something like {% printsection 
>  %} where  is the current Page object, and  name> is the name of the section you wish to print.
>
> So your homepage would looke something like this:
>
> 
> 
> {{ mypage.title }}
> 
> 
> {{ mypage.title }}
> {% printsection mypage "introduction" %}
>
> stuff goes here
>
> {% printsection mypage "footer" %}
> 
> 
>
> I'm sure you can come up with more specific and/or efficient variants
> on this theme, but basically this is going down the road that leads to
> content management systems, which have solved this basic problem for
> some time now :)
>
> Regards,
> Jeff
>
> Phil Powell wrote:
> >
> > Perhaps I've not explained myself properly.  Here's an example:
> >
> > I have a "Homepage" which has fields such as "Page Title",
> > "Introduction Text", "Footer Text" etc.  I want to be able to edit
> > these fields just like I'd edit a standard model instance, but because
> > there is only one instance of my "Homepage" I never want more than one
> > instance of it to exist.
> >
> > -Phil
>
>
> >
>

--~--~-~--~~~---~--~~
 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: Re: Re: Singleton model instance

2006-12-04 Thread James Bennett

On 12/4/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> I have a "Homepage" which has fields such as "Page Title",
> "Introduction Text", "Footer Text" etc.  I want to be able to edit
> these fields just like I'd edit a standard model instance, but because
> there is only one instance of my "Homepage" I never want more than one
> instance of it to exist.

So don't ever create more than one instance of it ;)

Regardless of feelings about the Singleton pattern (I'm not a fan),
though, this isn't really something that will have a clean solution in
Django, if it has a solution at all; because Django model classes map
to tables in a relational database, they carry with them the inherent
idea of being able to create multiple instances (which would then
correspond to multiple rows.

You *might* be able to hack something together using one of the
various attempts people have made at implementing Singleton in Python
[1], but I personally wouldn't recommend it.

[1] 
http://aspn.activestate.com/ASPN/search?query=singleton=0=0=PYTHONCKBK=Subsection

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
 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: Re: Singleton model instance

2006-12-04 Thread Phil Powell

On 04/12/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> I'm not sure I get how a singleton would solve the "pages generated from
> multiple chunks" problem.
>
> why not just use a model that holds (pagename, chunkname, chunk data)
> triplets, and use a view that brings up all the chunks for a given page ?

Perhaps I've not explained myself properly.  Here's an example:

I have a "Homepage" which has fields such as "Page Title",
"Introduction Text", "Footer Text" etc.  I want to be able to edit
these fields just like I'd edit a standard model instance, but because
there is only one instance of my "Homepage" I never want more than one
instance of it to exist.

-Phil

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