Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll try to answer your <em>actual</em> problem, because what you are asking for in the question is a problem with your proposed solution, which as many have pointed out is not really ideal.</p> <p>In the comments you mention this:</p> <blockquote> <p>i'll try to explain.. So we have 2 models: User and Book. A User has a book called "Titanic" with some content. Now, another user wants a relation to that book too. But, the second user wants exactly the same book, but it should be called "Ship is going under".. I would copy the book, and rename it. - I know, i could also put the content of the book in another model - but my model is a little bit more complex.</p> </blockquote> <p>Looks like you have three things to track:</p> <ol> <li>Users</li> <li>Their Books</li> <li>Some custom notes that users have about their "owned" book.</li> </ol> <p>For each <code>Book</code>, store its common information, for example:</p> <pre><code>class Author(models.Model): name = models.CharField(max_length=50) email = models.EmailField() def __unicode__(self): return unicode(self.name) class Book(models.Model): title = models.CharField(max_length=100) author = models.ManyToMany(Author) isbn = models.CharField(max_length=13) # and so on def __unicode__(self): return unicode(self.title) </code></pre> <p>Now, you need to store Book -> User relation, such as one user can have many books, two users may own the same book, with their own meta information attached.</p> <pre><code>class BookClub(models.Model): username = models.ForeignKey(User) book = models.ForeignKey(Book) comments = models.TextField() </code></pre> <p>If you structure your models like that, you'll be able to do queries like:</p> <ul> <li>"How many books does each member have?"</li> <li>"What is the most popular book?"</li> <li>"What is the least popular book?"</li> <li>"What is the most popular author?"</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload