summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-05-19 02:17:30 +0200
committerDan McGee <dan@archlinux.org>2012-05-19 02:58:27 +0200
commit17e33f9118e9749b1e3fdfd76686e85dbcecfb00 (patch)
treeab4620c41ec429b5b30040beda0b890d062bc12e /packages
parentae1c526ffbe908322f0dd8d8805360b81ab22b0f (diff)
downloadarchweb-17e33f9118e9749b1e3fdfd76686e85dbcecfb00.tar.gz
archweb-17e33f9118e9749b1e3fdfd76686e85dbcecfb00.tar.xz
Refactor an abstract base class out of conflicts/provides/replaces
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/models.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/packages/models.py b/packages/models.py
index 7a7a81c..f57c9f3 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -218,10 +218,10 @@ class License(models.Model):
class Meta:
ordering = ['name']
-class Conflict(models.Model):
- pkg = models.ForeignKey('main.Package', related_name='conflicts')
+
+class RelatedToBase(models.Model):
+ '''A base class for conflicts/provides/replaces/etc.'''
name = models.CharField(max_length=255, db_index=True)
- comparison = models.CharField(max_length=255, default='')
version = models.CharField(max_length=255, default='')
def __unicode__(self):
@@ -230,36 +230,29 @@ class Conflict(models.Model):
return self.name
class Meta:
+ abstract = True
ordering = ['name']
-class Provision(models.Model):
+
+class Conflict(RelatedToBase):
+ pkg = models.ForeignKey('main.Package', related_name='conflicts')
+ comparison = models.CharField(max_length=255, default='')
+
+
+class Provision(RelatedToBase):
pkg = models.ForeignKey('main.Package', related_name='provides')
- name = models.CharField(max_length=255, db_index=True)
# comparison must be '=' for provides
- comparison = '='
- version = models.CharField(max_length=255, default='')
- def __unicode__(self):
- if self.version:
- return u'%s=%s' % (self.name, self.version)
- return self.name
+ @property
+ def comparison(self):
+ if self.version is not None and self.version != '':
+ return '='
+ return None
- class Meta:
- ordering = ['name']
-class Replacement(models.Model):
+class Replacement(RelatedToBase):
pkg = models.ForeignKey('main.Package', related_name='replaces')
- name = models.CharField(max_length=255, db_index=True)
comparison = models.CharField(max_length=255, default='')
- version = models.CharField(max_length=255, default='')
-
- def __unicode__(self):
- if self.version:
- return u'%s%s%s' % (self.name, self.comparison, self.version)
- return self.name
-
- class Meta:
- ordering = ['name']
# hook up some signals