Re: Rendering a template according to model type

2007-04-25 Thread robin_percy

What about giving each Model a render() function to render it's
contents against it's template and return the resulting string.  You
could then do something like this in the Display template:

{% for e in elements %}
{{ e.render }}
{% endfor %}

A more MVC-friendly approach may be to render your Elements in the
Display view, and iterate through the resulting strings rather than
the objects.

-Robin

On Apr 24, 10:49 am, Jeremy Teale <[EMAIL PROTECTED]> wrote:
> I'm struggling with the template system.
>
> I have a Display model. This model will render its elements, which are
> of different model types. They are of type Addressbook, Schedule,
> Whiteboard, and so on.
>
> I'm trying to figure out how I can loop in the Display template and
> call each element's respective template tag to render the snippet.
>
>  For instance,
> {% for e in elements %}
>{{ e.call_respective_model_rendering_function }}
> {% endfor %}
>
> elements is a list of model objects of differing type
>
> I've been playing with inclusion tags, but what would be the proper
> way to determine the element's model type and then call the proper
> method?
>
> Here's an example of one of the inclusion tags I wrote to give a
> better idea of what I've been trying to do.
>
> @register.inclusion_tag('addressbook/display.html')
> def show_addressbook(addressbook):
> contacts = addressbook.contact_set.all()
> return {'name': addressbook.name, 'contacts': contacts}
>
> Can anyone help me, please?


--~--~-~--~~~---~--~~
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: Help with queryset

2007-04-24 Thread robin_percy

Looks like my earlier reply got dropped.  Sorry if this ends up being
a double post.

Check out the Model API docs: 
http://www.djangoproject.com/documentation/db-api/#isnull

You want to do something like:
Year.objects.filter(event__isnull=False)

- Robin

On Apr 24, 11:15 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I'll apologize in advance, as I just know this is a dumb question...
>
> I have queryset=Year.objects.all()
>
> But I want to limit that years in which event is not Null.
>
> I'm assuming I want something like Year.objects.filter(event != Null)
>
> but I'm unsure about the syntax.


--~--~-~--~~~---~--~~
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: Help with queryset

2007-04-24 Thread robin_percy

Not a dumb question, but one that has been answered in the Django
docs. Have a look at http://www.djangoproject.com/documentation/db-api/#isnull

It sounds like you want:
Year.objects.filter(event__isnull=False)

- Robin

On Apr 24, 11:15 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I'll apologize in advance, as I just know this is a dumb question...
>
> I have queryset=Year.objects.all()
>
> But I want to limit that years in which event is not Null.
>
> I'm assuming I want something like Year.objects.filter(event != Null)
>
> but I'm unsure about the syntax.


--~--~-~--~~~---~--~~
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: Need guidance on multiple domain site configuration.

2007-04-24 Thread robin_percy

I think everything could be accomplished by creating a separate
settings.py file for each site, and pointing to them in your virtual
hosts.  By installing your apps outside the project dirs, but still in
the PYTHON_PATH, you can refer to the same app dirs in all settings
files.  The only problem I can see is if you specify a different DB in
each settings.py, you'll need to create the same admin accounts in
each.

-Robin

On Apr 24, 7:22 am, Nick Tidey <[EMAIL PROTECTED]> wrote:
> Hello all.
>
> I'm creating a CMS/e-commerce Django project for a client which will
> ultimately be used to handle content for three different domains.
>
> In terms of sharing of resources:
> - content will not be shared between sites
> - public templates will differ between sites
> - the administration interface is the same for all sites (a customised
> version of the Django administration interface)
> - each site will use the same group of Django apps
> - the client would like administration user accounts to be shared
> across all sites
> - I would like each site to at least use a separate set of tables;
> preferably separate databases
>
> I'm new to Django and I've read up on Django's site framework; read
> about various Apache configurations, searched for information on
> multiple database connections in Django, etc. There's a lot to take
> in.
>
> I'm hoping someone can suggest a way to handle this.
>
> I'm looking to host the sites on a WebFaction shared account.
>
> Thanks
> Nick


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

2007-04-24 Thread robin_percy



On Apr 24, 10:58 am, Moses Ting <[EMAIL PROTECTED]> wrote:
> Hello DJ Users,
>
> I'm trying to write a generic template where I can auto-populate a
> html table depending on which model I use.  So for example the view
> does something like this:
>
> def genericView(request, model):
>  context = {}
>
>  fields = model._meta.fields
>  fieldNames = []
>  for field in fields:
>   fieldNames.append(field.get_attname())
>  context.update({'fields': fieldNames})
>
>  records = model.objects.all()
>  context.update({'records': records})
>
> return render_to_response('template.html', context)
>
> The problem I'm running into occurs when I'm trying to dynamically
> retrieve the field value of a particular record.  So let's say I want
> to retrieve the values from all the fields of all the records, the
> template would look something like this:
>
> template.html-
>
> {% for record in records %}
> {% for field in fields %}
> {{record.field}}
>
> There's no way to do this because {{record.field}} does not work.
> Nesting the curly brackets like {{record.{{field}}} also is no good.
>
> Any suggestions?

I think you're trying to do too much in the template.  Instead of
passing the two separate lists, you could create a 2D list and pass it
instead. For example,

def genericView(request,model):
fieldNames = [field.attname for field in model._meta.fields]
record_rows = []
for rec in model.objects.all():
cur_rec = [ getattr(rec,f_name) for f_name in fieldNames]
record_rows.append(cur_rec)

context = {'record_rows': record_rows}
return render_to_response('test/template.html', context) )
-Template.html---

{% for record in record_rows %}

{% for field in record %}
{{ field }}
{% endfor %}

{% endfor %}



--~--~-~--~~~---~--~~
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 and file uploads question

2007-04-24 Thread robin_percy

On Apr 24, 9:14 am, "Craig Kuhns" <[EMAIL PROTECTED]> wrote:

> Does any one have any idea what that error is from.  I am at work
> right now, but tonight I am going to dig in and see if I can find it,
> but if anyone has any ideas they would be much appreciated.
>

Craig,

It sounds like the bug described here: http://code.djangoproject.com/ticket/2923
. What version of Django are you using?

- Robin


--~--~-~--~~~---~--~~
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: audit trail support

2007-04-23 Thread robin_percy

What about doing both?  Write a pre_save record indicating the
operation about to be attempted.  And a post_save indicating the
success of the operation, using a unique identifier to identify the
pair.  Then if the post_save gets out of sync, you have a record of
transactions that may be at fault.

Just my two cents.

- Robin

On Apr 23, 2:07 pm, "Jason McVetta" <[EMAIL PROTECTED]> wrote:
> On 4/23/07, David Larlet <[EMAIL PROTECTED]> wrote:
>
>
>
> > It's a bit ugly to declare instance hidden variables (pre) but we need to
> > be
> > sure that the save/delete is effective (post) before logging it.
>
> It's not beautiful, perhaps, but I may end up doing something very similar.
> However, one requirement of my project is that the audit tables not require
> UPDATE or DELETE permission.  Which begs the question, if I write my audit
> record on the pre_save signal, how do I record the success or failure of the
> save() operation?
>
> Alternatively, I could write the audit record on post_save.  Although I
> can't think off the top of my head of an example where this would get out of
> sync with the main table, something about it feels risky.  But I will have
> to think about this one some more.


--~--~-~--~~~---~--~~
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 and file uploads question

2007-04-23 Thread robin_percy

Craig,

Not sure what would be causing your error.  But to answer your second
question, your files should automatically be uploaded by the
FileField.  As long as the web server has write access, the files
should be uploaded to MEDIA_ROOT/upload_to where upload_to is the
argument to your file field.

Check out http://www.djangoproject.com/documentation/model-api/#filefield

-Robin

On Apr 23, 1:02 pm, "Craig Kuhns" <[EMAIL PROTECTED]> wrote:
> Hey every one.  I am pretty new to Python and Django coming over from
> Ruby on Rails.  I am creating an app where different ministries will
> have profiles on a site and each profile will have a logo or picture
> associated with it.  The site is far from going live but I am working
> on getting the basic functionality going right now.
>
> I decided that for beginning purposes I would use a FileField in my
> models instead of an ImageField so that i can get the uploads working
> right and then worry about moving to an ImageField.  My
> question/problem is this...
>
> When creating a new profile in the admin I can tell the file upload
> box to take any file that I want but when I go to edit a profile and
> tell it to use a differen file from the one already specified it comes
> back with an error telling me to use a valid filename.  It only
> happens if a filename is already saved into the database.  In fact if
> I have already uploaded a file then I can never edit that record
> because everytime I go to save the edits I get that error.
>
> The other question I have is about the actual file uploading.  All the
> FileField does is saves the url of the file to a column in the
> database I understand that.  What do i have to do to have the file
> actually uploaded.  In the settings file I added a media root and a
> media url.  What else do I have to do?
>
> Thanks
>
> Craig


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