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:
commit
ee0e239a9e
@ -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):
|
||||
'''
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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], [])
|
||||
|
Loading…
Reference in New Issue
Block a user