pbaranay / django-magic-cards

A pluggable Django app for the Oracle text of all Magic: the Gathering cards
MIT License
7 stars 1 forks source link

Implement @property Card.typeline #4

Open dcollinsn opened 7 years ago

dcollinsn commented 7 years ago

A typeline @property on class Card which correctly orders supertypes, types, and subtypes, inserting a dash between types and subtypes if there are subtypes, would be useful, and I think it would be appropriate for this package.

@property
def typeline(self):
    typeline = ''
    if self.supertypes.exists():
        typeline += ' '.join(self.supertypes.values_list('name', flat=True))
        typeline += ' '
    typeline += ' '.join(self.types.values_list('name', flat=True))
    if self.subtypes.exists():
        typeline += ' – ' + ' '.join(self.subtypes.values_list('name', flat=True))
    return typeline

No idea if there's a correct sorting for any of the types of types, but if there is, it should probably be added to the class Meta in models.py?

pbaranay commented 7 years ago

I can add this.

Wizards does appear to have a fairly consistent way of ordering various subtypes among themselves, but the method is not readily transparent. The most accurate way to handle this would involve storing the actual type line from Oracle. This also eases the load on the database, as we're not repeatedly building the typeline on the fly.