Model Relationship Causing Error

2009-03-22 Thread Super McFly

This is a bit of a tricky one but I need help solving the following
error:

ImportError: cannot import name Container

I'm sure it has something to do with the unusual relationships I have
between two models. I'll put a simplified version below.

It started when I added the 'image' field to the container model.

*** media/models.py ***

from django.db import models, transaction, IntegrityError
from django.contrib.auth.models import User
from myproject.containers.models import Container
import tempfile

class Image(models.Model):
title = models.CharField('title', max_length=255)
image = models.ImageField(upload_to='uploads/images')
caption = models.TextField(blank=True)
profiles = models.ManyToManyField(Container, limit_choices_to =
{'container_type__url': 'profiles'}, related_name='image_profiles',
blank=True)

*** end ***

*** containers/models.py ***

from django.db import models
from django.contrib.auth.models import User
from myproject.media.models import Image

class Container(models.Model):
title = models.CharField(max_length=255)
url = models.CharField(max_length=64)
image = models.ForeignKey(Image, blank=True, null=True,
related_name='profile_image')
description = models.CharField(max_length=255, blank=True)
user = models.ForeignKey(User, null=True, blank=True)

*** end ***

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



Re: Model Relationship Causing Error

2009-03-22 Thread Super McFly

> The solutions isn't too hard, though. Use the "string format" for
> referencing from, say, Image -> Container. 
> Seehttp://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkeyfor
> documentation about this.

Thank you for replying. I tried that method before but I received an
error saying it " has either not been installed or is abstract".

Of course I was just doing something silly. I was using
'myproject.media.models.Image' when I only needed 'media.Image'. It's
still not clear to me why this format is used but it works.

I actually ran into this problem sometime last year and it caused me
to give up. But now I'm back, and hopefully I'll be the one giving
advice next time.

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



Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
Is it possible to use a template variable in the "include" template
tag. My actual problem is below...

{% include "content/{{ content.model_type }}/include.html" %}

{{ content.model_type }} by itself outputs "post" and the full string
outputs "content/post/include.html" and if that string is hard-coded
then the template is included.

-- 
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: Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
Thank you for the reply. Do you have any suggestions on how to do it
my way?

On Jan 30, 5:23 am, pyleaf  wrote:
> i think that will not work,because 'include' excutes before the Variable.
>
> On Sat, Jan 30, 2010 at 12:51 PM, Super McFly wrote:
>
>
>
> > Is it possible to use a template variable in the "include" template
> > tag. My actual problem is below...
>
> > {% include "content/{{ content.model_type }}/include.html" %}
>
> > {{ content.model_type }} by itself outputs "post" and the full string
> > outputs "content/post/include.html" and if that string is hard-coded
> > then the template is included.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> 相信那一片天空会因你的执着而晴朗

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



Re: Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
I guess the only way to do this would be to use an if conditional,
which would be really ugly...

{% if content.model_type == 'post' %}
{% include "content/post/include.html" %}
{% endif %}

{% if content.model_type == 'review' %}
{% include "content/review/include.html" %}
{% endif %}



On Jan 30, 5:33 am, Super McFly  wrote:
> Thank you for the reply. Do you have any suggestions on how to do it
> my way?
>
> On Jan 30, 5:23 am, pyleaf  wrote:
>
> > i think that will not work,because 'include' excutes before the Variable.
>
> > On Sat, Jan 30, 2010 at 12:51 PM, Super McFly wrote:
>
> > > Is it possible to use a template variable in the "include" template
> > > tag. My actual problem is below...
>
> > > {% include "content/{{ content.model_type }}/include.html" %}
>
> > > {{ content.model_type }} by itself outputs "post" and the full string
> > > outputs "content/post/include.html" and if that string is hard-coded
> > > then the template is included.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> > --
> > 相信那一片天空会因你的执着而晴朗

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



Re: Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
I had just responded to myself with that suggestion but I've deleted
it to avoid repetition.

I'll try to explain the bigger picture but it's a little tricky. There
is a "Content" base model from which "Post", "Review", "Feature",
e.t.c inherit. To get a list of the latest content for all types I
have a view which renders "content_list = get_list_or_404(Content)" to
a template. In that template I loop over "content_list" and want to
include a specific template for each content type (post, review,
feature).

*** view ***
...
def content_list(request):
content_list = get_list_or_404(Content)
return render_to_response('content/content/list.html',
{'content_list': content_list}, context_instance=RequestContext
(request))
...

*** content/content/list.html ***
...
{% for content in content_list %}
{% include "content/{{ content.model_type }}/include.html" %}
{% endfor %}
...

*** content/review/include.html ***
...
{{ content.introduction|linebreaks }}
{{ content.body|linebreaks }}
{{ content.verdict|linebreaks }}
{{ content.score }}
...


On Jan 30, 5:37 am, Sam Lai  wrote:
> You can always use if blocks, e.g.
>
> {% ifequal content.model_type "post" %}
> {% include "content/post/include.html" %}
> {% elseifequal ... %}
> ...
> {% endif %}
>
> What's the bigger picture for what you're trying to do?
>
> 2010/1/30 Super McFly :
>
> > Thank you for the reply. Do you have any suggestions on how to do it
> > my way?
>
> > On Jan 30, 5:23 am, pyleaf  wrote:
> >> i think that will not work,because 'include' excutes before the Variable.
>
> >> On Sat, Jan 30, 2010 at 12:51 PM, Super McFly 
> >> wrote:
>
> >> > Is it possible to use a template variable in the "include" template
> >> > tag. My actual problem is below...
>
> >> > {% include "content/{{ content.model_type }}/include.html" %}
>
> >> > {{ content.model_type }} by itself outputs "post" and the full string
> >> > outputs "content/post/include.html" and if that string is hard-coded
> >> > then the template is included.
>
> >> > --
> >> > You received this message because you are subscribed to the Google Groups
> >> > "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > django-users+unsubscr...@googlegroups.com
> >> > .
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/django-users?hl=en.
>
> >> --
> >> 相信那一片天空会因你的执着而晴朗
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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



Re: Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
Thanks for your suggestion, Eric. I actually tried that but for some
reason it didn't work so I assumed it was the same problem. It turns
out it does work so a big thank you to you and everyone else who tried
to help.

On Jan 30, 5:59 am, Eric Abrahamsen  wrote:
> I've done this by including a python-only attribute on the models  
> themselves:
>
> include_template = "content/post/include.html"
>
> and in the template {% include content.include_template %}
>
> Provided that "content" is a model instance.
>
> You could even write a model mixin class that does this automatically,  
> populating the include_template attribute using string formatting and  
> the class name.
>
> Eric
>
> On Jan 30, 2010, at 1:45 PM, Super McFly wrote:
>
> > I guess the only way to do this would be to use an if conditional,
> > which would be really ugly...
>
> > {% if content.model_type == 'post' %}
> >{% include "content/post/include.html" %}
> > {% endif %}
>
> > {% if content.model_type == 'review' %}
> >{% include "content/review/include.html" %}
> > {% endif %}
>
> > On Jan 30, 5:33 am, Super McFly  wrote:
> >> Thank you for the reply. Do you have any suggestions on how to do it
> >> my way?
>
> >> On Jan 30, 5:23 am, pyleaf  wrote:
>
> >>> i think that will not work,because 'include' excutes before the  
> >>> Variable.
>
> >>> On Sat, Jan 30, 2010 at 12:51 PM, Super McFly  
> >>> wrote:
>
> >>>> Is it possible to use a template variable in the "include" template
> >>>> tag. My actual problem is below...
>
> >>>> {% include "content/{{ content.model_type }}/include.html" %}
>
> >>>> {{ content.model_type }} by itself outputs "post" and the full  
> >>>> string
> >>>> outputs "content/post/include.html" and if that string is hard-
> >>>> coded
> >>>> then the template is included.
>
> >>>> --
> >>>> You received this message because you are subscribed to the  
> >>>> Google Groups
> >>>> "Django users" group.
> >>>> To post to this group, send email to django-us...@googlegroups.com.
> >>>> To unsubscribe from this group, send email to
> >>>> django-users+unsubscr...@googlegroups.com
> >>>> .
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/group/django-users?hl=en.
>
> >>> --
> >>> 相信那一片天空会因你的执着而晴朗
>
> > --
> > You received this message because you are subscribed to the Google  
> > Groups "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en
> > .

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



Re: Using a template variable in the "include" template tag

2010-01-29 Thread Super McFly
I store the model name as a field in the "Content" class. I then added

def include_template(self):
return"content/" + self.content_type.lower() + "/include.html"

to the model. Then in the template I used

{% for content in content_list %}
{% include content.include_template %}
{% endfor %}


On Jan 30, 6:19 am, Eric Abrahamsen  wrote:
> On Jan 30, 2010, at 2:07 PM, Super McFly wrote:
>
> > Thanks for your suggestion, Eric. I actually tried that but for some
> > reason it didn't work so I assumed it was the same problem. It turns
> > out it does work so a big thank you to you and everyone else who tried
> > to help.
>
> Good!
>
> Since you've already got a Content superclass going you could probably  
> do some metaclass jiggery-pokery to make this automatic for subclasses  
> ¨C on reflection it wouldn't be as simple as I blithely suggested in my  
> last response, but I think it could be done.
>
> E
>
>
>
> > On Jan 30, 5:59 am, Eric Abrahamsen  wrote:
> >> I've done this by including a python-only attribute on the models
> >> themselves:
>
> >> include_template = "content/post/include.html"
>
> >> and in the template {% include content.include_template %}
>
> >> Provided that "content" is a model instance.
>
> >> You could even write a model mixin class that does this  
> >> automatically,
> >> populating the include_template attribute using string formatting and
> >> the class name.
>
> >> Eric
>
> >> On Jan 30, 2010, at 1:45 PM, Super McFly wrote:
>
> >>> I guess the only way to do this would be to use an if conditional,
> >>> which would be really ugly...
>
> >>> {% if content.model_type == 'post' %}
> >>>   {% include "content/post/include.html" %}
> >>> {% endif %}
>
> >>> {% if content.model_type == 'review' %}
> >>>   {% include "content/review/include.html" %}
> >>> {% endif %}
>
> >>> On Jan 30, 5:33 am, Super McFly  wrote:
> >>>> Thank you for the reply. Do you have any suggestions on how to do  
> >>>> it
> >>>> my way?
>
> >>>> On Jan 30, 5:23 am, pyleaf  wrote:
>
> >>>>> i think that will not work,because 'include' excutes before the
> >>>>> Variable.
>
> >>>>> On Sat, Jan 30, 2010 at 12:51 PM, Super McFly
> >>>>> wrote:
>
> >>>>>> Is it possible to use a template variable in the "include"  
> >>>>>> template
> >>>>>> tag. My actual problem is below...
>
> >>>>>> {% include "content/{{ content.model_type }}/include.html" %}
>
> >>>>>> {{ content.model_type }} by itself outputs "post" and the full
> >>>>>> string
> >>>>>> outputs "content/post/include.html" and if that string is hard-
> >>>>>> coded
> >>>>>> then the template is included.
>
> >>>>>> --
> >>>>>> You received this message because you are subscribed to the
> >>>>>> Google Groups
> >>>>>> "Django users" group.
> >>>>>> To post to this group, send email to django-users@googlegroups.com
> >>>>>> .
> >>>>>> To unsubscribe from this group, send email to
> >>>>>> django-users+unsubscr...@googlegroups.com
> >>>>>> .
> >>>>>> For more options, visit this group at
> >>>>>>http://groups.google.com/group/django-users?hl=en.
>
> >>>>> --
> >>>>> ÏàÐÅÄÇһƬÌì¿Õ»áÒòÄãµÄÖ´×ŶøÇçÀÊ
>
> >>> --
> >>> You received this message because you are subscribed to the Google
> >>> Groups "Django users" group.
> >>> To post to this group, send email to django-us...@googlegroups.com.
> >>> To unsubscribe from this group, send email to 
> >>> django-users+unsubscr...@googlegroups.com
> >>> .
> >>> For more options, visit this group 
> >>> athttp://groups.google.com/group/django-users?hl=en
> >>> .
>
> > --
> > You received this message because you are subscribed to the Google  
> > Groups "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en
> > .

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



Re: Using a template variable in the "include" template tag

2010-01-30 Thread Super McFly
You have been able to use if statements as far back as I can remember
using django (over a year). You might as well finish posting your
actual problem since you're here and I'll try to help.

As for your version problem you more than likely have the latest
development version. I notice the same thing despite having the latest
code.

On Jan 30, 4:23 pm, shofty  wrote:
> On Jan 30, 5:37 am, Sam Lai  wrote:
>
> > You can always use if blocks, e.g.
>
> > {% ifequal content.model_type "post" %}
> > {% include "content/post/include.html" %}
> > {% elseifequal ... %}
> > ...
> > {% endif %}
>
> I believe im right in saying that you can only use if statements in
> tags when using the development django codebase.
> cos thats what i've read in the docco, but even so i cant get it
> working against the development code.
>
> another question if i may as its relevant and someone may know the
> answer. if you install the dev code from subversion, when you start
> the server does it still report itself as version 1.2 alpha 1 or have
> i got a problem installing my dev version.
>
> Matt

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