Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-table inheritance #17

Open
danxshap opened this issue Aug 18, 2013 · 6 comments
Open

Multi-table inheritance #17

danxshap opened this issue Aug 18, 2013 · 6 comments

Comments

@danxshap
Copy link
Contributor

I have models like this:

class SubUnit(models.Model):
   # .... some fields

class Task(models.Model):
    """
    Base class for lessons/exercises - ordered items within a sub-unit
    """
    sub_unit = models.ForeignKey(SubUnit)
    position = PositionField(collection='sub_unit')

class Lesson(Task):
    # ... lesson-specific fields

class Exercise(Task):
    # ... exercise-specific fields

Basically a SubUnit contains many Task's, each of which may be a Lesson or an Exercise. I'd like to keep track of the position of each Task regardless of whether it's a Lesson or an Exercise. If I add a Lesson, it has position 0, and then if I add an Exercise to the same SubUnit I expect/want it to have position 1, but it instead has position 0 - the Lesson position counter is totally separate from the Exercise position counter.

Do you know of any workarounds for this?

Thank you!

jpwatts added a commit that referenced this issue Aug 20, 2013
@jpwatts
Copy link
Owner

jpwatts commented Aug 20, 2013

Could you take a look at 1b84890 and see if it does what you need? It seems like there are legitimate reasons to want child models to be ordered independently as well as reasons to want them all to be part of the same sequence, so I added an argument to make it configurable. I stuck with independent ordering as the default, mostly to preserve backwards compatibility.

@danxshap
Copy link
Contributor Author

Thanks for the quick response!

Hmmm, seems like I'm running into some unexpected behavior. I also can't figure out how to run the tests...if I do python manage.py test positions I get ImproperlyConfigured: App with label positions is missing a models.py module.

Your commit seems to have fixed the scenario in which I'm appending lessons/exercises (i.e. creating them without specifying position), but it looks like even before the commit there was an issue that I didn't notice at first.

If I create Lesson (0), Lesson (1), Lesson (2), and then I do Lesson.objects.create(sub_unit=same_sub_unit, name='whatever', position = 0), it's not updating the existing 0/1/2 to 1/2/3 like it does for simple models that don't use multi-table inheritance...

Happy to play around with it further and write up failing test cases once I can actually run the tests - any ideas there?

Thanks again!

@jpwatts
Copy link
Owner

jpwatts commented Aug 20, 2013

I run the tests like this:

django-admin.py test --settings=positions.examples.settings

Thanks for being willing to dig in a bit. In the spirit of full disclosure, I should probably tell you that I wrote this code a long time ago and I'm not using it in any current projects, so it doesn't exactly have my full attention. That said, I've tried to keep it working on current versions of Django and to fix bugs as they're identified. If you've got the interest and energy, pull requests are absolutely welcome.

@danxshap
Copy link
Contributor Author

danxshap commented Dec 3, 2013

just curious @jpwatts has this been fixed?

@jpwatts
Copy link
Owner

jpwatts commented Dec 3, 2013

Sorry; that was sloppy of me. I was trying to clean up a bit around here and wasn't seeing your test fail, but I didn't catch that Django 1.6 wasn't running the doctests. That's fixed now, but this issue is still open.

@jpwatts jpwatts reopened this Dec 3, 2013
@danxshap
Copy link
Contributor Author

danxshap commented Dec 3, 2013

Good stuff, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants