Skip to content

Commit

Permalink
work on models
Browse files Browse the repository at this point in the history
  • Loading branch information
marios-zindilis committed Nov 24, 2017
1 parent f739e1b commit 31fd8f9
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 37 deletions.
17 changes: 17 additions & 0 deletions _docs/area_attribute.rst
@@ -0,0 +1,17 @@
area_attribute
==============

.. automodule:: musicbrainz_django_models.models.area_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.area_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/area_attribute.py
:pyobject: area_attribute
:caption: The `area_attribute` Model
17 changes: 17 additions & 0 deletions _docs/artist_attribute.rst
@@ -0,0 +1,17 @@
artist_attribute
================

.. automodule:: musicbrainz_django_models.models.artist_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.artist_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/artist_attribute.py
:pyobject: artist_attribute
:caption: The `artist_attribute` Model
17 changes: 17 additions & 0 deletions _docs/event_attribute.rst
@@ -0,0 +1,17 @@
event_attribute
===============

.. automodule:: musicbrainz_django_models.models.event_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.event_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/event_attribute.py
:pyobject: event_attribute
:caption: The `event_attribute` Model
17 changes: 17 additions & 0 deletions _docs/instrument_attribute.rst
@@ -0,0 +1,17 @@
instrument_attribute
====================

.. automodule:: musicbrainz_django_models.models.instrument_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.instrument_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/instrument_attribute.py
:pyobject: instrument_attribute
:caption: The `instrument_attribute` Model
17 changes: 17 additions & 0 deletions _docs/label_attribute.rst
@@ -0,0 +1,17 @@
label_attribute
===============

.. automodule:: musicbrainz_django_models.models.label_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.label_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/label_attribute.py
:pyobject: label_attribute
:caption: The `label_attribute` Model
17 changes: 17 additions & 0 deletions _docs/medium_attribute.rst
@@ -0,0 +1,17 @@
medium_attribute
================

.. automodule:: musicbrainz_django_models.models.medium_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.medium_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/medium_attribute.py
:pyobject: medium_attribute
:caption: The `medium_attribute` Model
17 changes: 17 additions & 0 deletions _docs/medium_attribute_type_allowed_format.rst
@@ -0,0 +1,17 @@
medium_attribute_type_allowed_format
====================================

.. automodule:: musicbrainz_django_models.models.medium_attribute_type_allowed_format
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.medium_attribute_type_allowed_format

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/medium_attribute_type_allowed_format.py
:pyobject: medium_attribute_type_allowed_format
:caption: The `medium_attribute_type_allowed_format` Model
17 changes: 17 additions & 0 deletions _docs/medium_attribute_type_allowed_value_allowed_format.rst
@@ -0,0 +1,17 @@
medium_attribute_type_allowed_value_allowed_format
==================================================

.. automodule:: musicbrainz_django_models.models.medium_attribute_type_allowed_value_allowed_format
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.medium_attribute_type_allowed_value_allowed_format

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/medium_attribute_type_allowed_value_allowed_format.py
:pyobject: medium_attribute_type_allowed_value_allowed_format
:caption: The `medium_attribute_type_allowed_value_allowed_format` Model
17 changes: 17 additions & 0 deletions _docs/place_attribute.rst
@@ -0,0 +1,17 @@
place_attribute
===============

.. automodule:: musicbrainz_django_models.models.place_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.place_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/place_attribute.py
:pyobject: place_attribute
:caption: The `place_attribute` Model
17 changes: 17 additions & 0 deletions _docs/recording_attribute.rst
@@ -0,0 +1,17 @@
recording_attribute
===================

.. automodule:: musicbrainz_django_models.models.recording_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.recording_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/recording_attribute.py
:pyobject: recording_attribute
:caption: The `recording_attribute` Model
17 changes: 17 additions & 0 deletions _docs/release_attribute.rst
@@ -0,0 +1,17 @@
release_attribute
=================

.. automodule:: musicbrainz_django_models.models.release_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.release_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/release_attribute.py
:pyobject: release_attribute
:caption: The `release_attribute` Model
17 changes: 17 additions & 0 deletions _docs/release_group_attribute.rst
@@ -0,0 +1,17 @@
release_group_attribute
=======================

.. automodule:: musicbrainz_django_models.models.release_group_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.release_group_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/release_group_attribute.py
:pyobject: release_group_attribute
:caption: The `release_group_attribute` Model
17 changes: 17 additions & 0 deletions _docs/series_attribute.rst
@@ -0,0 +1,17 @@
series_attribute
================

.. automodule:: musicbrainz_django_models.models.series_attribute
:noindex:

Model Documentation
-------------------

.. autoclass:: musicbrainz_django_models.models.series_attribute

Model Source
------------

.. literalinclude:: ../musicbrainz_django_models/models/series_attribute.py
:pyobject: series_attribute
:caption: The `series_attribute` Model
39 changes: 25 additions & 14 deletions musicbrainz_django_models/models/abstract/model_type.py
@@ -1,8 +1,26 @@
"""
.. module:: abstract__model_type
This is an Abstract Django Model, meant to be subclassed by Models that store
the *type* of other models, or the *type* of other models' aliases, namely:
This is an Abstract Django Model, meant to be subclassed by other Models.
Model Types
~~~~~~~~~~~
1. :class:`area_type`
2. :class:`artist_type`
3. :class:`event_type`
4. :class:`instrument_type`
5. :class:`label_type`
6. :class:`place_type`
7. :class:`series_type`
8. :class:`work_type`
9. :class:`release_group_primary_type`
10. :class:`release_group_secondary_type`
11. :class:`alternative_release_type`
12. :class:`series_ordering_type`
Model Alias Types
~~~~~~~~~~~~~~~~~
1. :class:`area_alias_type`
2. :class:`artist_alias_type`
Expand All @@ -15,18 +33,11 @@
9. :class:`release_group_alias_type`
10. :class:`series_alias_type`
11. :class:`work_alias_type`
12. :class:`area_type`
13. :class:`artist_type`
14. :class:`event_type`
15. :class:`instrument_type`
16. :class:`label_type`
17. :class:`place_type`
18. :class:`series_type`
19. :class:`work_type`
20. :class:`release_group_primary_type`
21. :class:`release_group_secondary_type`
22. :class:`alternative_release_type`
23. :class:`series_ordering_type`
Other
~~~~~
1. :class:`gender`
These models are defined in the MusicBrainz Server as:
Expand Down
28 changes: 5 additions & 23 deletions musicbrainz_django_models/models/gender.py
Expand Up @@ -35,19 +35,12 @@

from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import uuid


def pre_save_gender(sender, instance, **kwargs):
if instance.name not in sender.NAME_CHOICE_LIST:
from django.core.exceptions import ValidationError
raise ValidationError('Gender "{}" is not one of: {}'.format(
instance.name,
', '.join(sender.NAME_CHOICE_LIST)))
from ..signals import pre_save_name_is_member_of_name_choices_list
from . import abstract


@python_2_unicode_compatible
class gender(models.Model):
class gender(abstract.model_type):
"""
Not all parameters are listed here, only those that present some interest
in their Django implementation.
Expand All @@ -57,9 +50,6 @@ class gender(models.Model):
3 possible values: "Male", "Female" and "Other". This is implemented
in Django with a `choices` parameter to the `name` field, as well as
with a `pre_save` signal for validation.
:param gid: this is interesting because it cannot be NULL but a default is
not defined in SQL. The default `uuid.uuid4` in Django will generate a
UUID during the creation of an instance.
"""

MALE = 'Male'
Expand All @@ -70,20 +60,12 @@ class gender(models.Model):
(FEMALE, FEMALE),
(OTHER, OTHER),
)
NAME_CHOICE_LIST = [_[0] for _ in NAME_CHOICES]
NAME_CHOICES_LIST = [_[0] for _ in NAME_CHOICES]

id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255, choices=NAME_CHOICES)
parent = models.ForeignKey('self', null=True)
child_order = models.IntegerField(default=0)
description = models.TextField(null=True)
gid = models.UUIDField(default=uuid.uuid4)

def __str__(self):
return self.name

class Meta:
db_table = 'gender'


models.signals.pre_save.connect(pre_save_gender, sender=gender)
models.signals.pre_save.connect(pre_save_name_is_member_of_name_choices_list, sender=gender)

0 comments on commit 31fd8f9

Please sign in to comment.