1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Merge pull request #1374 from AlanCoding/your_name

More consistent representations of model objects
This commit is contained in:
Alan Rominger 2018-02-28 09:08:29 -05:00 committed by GitHub
commit ee0e239a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 12 deletions

View File

@ -93,10 +93,10 @@ class BaseModel(models.Model):
abstract = True
def __unicode__(self):
if hasattr(self, 'name'):
return u'%s-%s' % (self.name, self.id)
if 'name' in self.__dict__:
return u'%s-%s' % (self.name, self.pk)
else:
return u'%s-%s' % (self._meta.verbose_name, self.id)
return u'%s-%s' % (self._meta.verbose_name, self.pk)
def clean_fields(self, exclude=None):
'''

View File

@ -596,9 +596,6 @@ class Host(CommonModelNameNotUnique):
objects = HostManager()
def __unicode__(self):
return self.name
def get_absolute_url(self, request=None):
return reverse('api:host_detail', kwargs={'pk': self.pk}, request=request)
@ -768,9 +765,6 @@ class Group(CommonModelNameNotUnique):
help_text=_('Inventory source(s) that created or modified this group.'),
)
def __unicode__(self):
return self.name
def get_absolute_url(self, request=None):
return reverse('api:group_detail', kwargs={'pk': self.pk}, request=request)

View File

@ -74,9 +74,6 @@ class Organization(CommonModel, NotificationFieldsModel, ResourceMixin, CustomVi
def get_absolute_url(self, request=None):
return reverse('api:organization_detail', kwargs={'pk': self.pk}, request=request)
def __unicode__(self):
return self.name
class Team(CommonModelNameNotUnique, ResourceMixin):
'''

View File

@ -153,6 +153,12 @@ class Role(models.Model):
object_id = models.PositiveIntegerField(null=True, default=None)
content_object = GenericForeignKey('content_type', 'object_id')
def __unicode__(self):
if 'role_field' in self.__dict__:
return u'%s-%s' % (self.name, self.pk)
else:
return u'%s-%s' % (self._meta.verbose_name, self.pk)
def save(self, *args, **kwargs):
super(Role, self).save(*args, **kwargs)
self.rebuild_role_ancestor_list([self.id], [])