Hey guys, I'm developing some models for a project and I'm running
into some issues and I'm wondering if perhaps I'm way off base with
how I'm approaching the design.  Here's how things should work, in
words:

A UserProfile can have many ImageObjects associated to it
A UserProfile can have many VideoObjects associated to it
A UserProfile can have many URLObjects associated to it
An ImageObject can belong to a single UserProfile
A VideoObject can belong to a single UserProfile
A URLObject can belong to a single UserProfile

and for the kicker...

A UserProfile can have a single ImageObject associated with it for use
as a profile image.

*** Oh, and I have my profile models in one app and my content models
in another app.

This is how I had it (obviously simplified) and I was running into
some issues, plus I felt it didn't specifically adhere to the
situation above as an *Object could belong to multiple users:

---[ myproj.profile.models ]---
from myproj.content.models import ImageObject, VideoObject, URLObject

class UserProfile(models.Model):
  profile_image = models.ForeignKey(ImageObject, related_name='profile_image')
  images = models.ManyToManyField(ImageObject, related_name='images')
  videos = models.ManyToManyField(VideoObject)
  urls = models.ManyToManyField(URLObject)
---------------------------------------

---[ myproj.content.models ]---
class ImageObject(models.Model):
  name = models.CharField()
  uri = models.ImageField()

class VideoObject(models.Model):
  name = models.CharField()
  uri = models.FileField()

class URLObject(models.Model):
  name = models.CharField()
  uri = models.URLField()
---------------------------------------

So then I changed how I did it to this model, to try and enforce the
"a profile can have many images and a picture can only have 1
UserProfile" restraint above:

---[ myproj.profile.models ]---
from myproj.myapp.models import ImageObject

class UserProfile(models.Model):
  profile_image = models.ForeignKey(ImageObject, related_name='profile_image')
----------------------------------------

---[ myproj.content.models ]---
class ImageObject(models.Model):
  name = models.CharField()
  uri = models.ImageField()
  user = models.ForeignKey(UserProfile)

class VideoObject(models.Model):
  name = models.CharField()
  uri = models.FileField()
  user = models.ForeignKey(UserProfile)

class URLObject(models.Model):
  name = models.CharField()
  uri = models.URLField()
  user = models.ForeignKey(UserProfile)
----------------------------------------

However, at this point I'm getting errors in th dev-server and they
models disappear from the administrative interface:

---
Validating models...
stoneward_intranet.profile: cannot import name UserProfile
stoneward_intranet.content: cannot import name ImageObject
2 errors found.
---

I get the same errors from the shell and I'm wondering if this has
something to do with each model importing the other and it running
into some sort of loop?  Am I taking the fundamentally wrong approach
or do I need to work around this behavior?

thanks!

Clint Ecker

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

Reply via email to