How to use admin_description method in autotest

Best Python code snippet using autotest_python

admin.py

Source:admin.py Github

copy

Full Screen

...73 )74 resource_class = ProductResource75 save_on_top = True76 @mark_safe77 def admin_description(self, obj):78 return '<div style="max-width:300px">%s<div>' % obj.description79 @mark_safe80 def view_on_site(self, obj):81 url = reverse('products', kwargs={'category_name': obj.category.sku})82 return '<a class="button" target="_blank" href="http://vvvvovvvv.com%s">View</a>' % url83 def toggle_publish(self, request, queryset):84 queryset.update(publish=True)85 view_on_site.allow_tags = True86 admin_description.allow_tags = True87 view_on_site.short_description = 'View on Site'88 admin_description.short_description = 'Description'89@admin.register(Press)90class PressAdmin(SortableAdmin, ImportExportModelAdmin):91 list_display = (92 'publish',93 'title',94 'date_article',95 'date',96 'view_on_site',97 )98 list_editable = ('publish', 'date_article')99 list_display_links = ('title', )100 inlines = [pressImageInline, pressVideoInline]101 search_fields = (102 'title',103 'slug',104 )105 @mark_safe106 def view_on_site(self, obj):107 url = reverse('press_single', kwargs={'press_name': obj.slug})108 return '<a class="button" target="_blank" href="http://vvvvovvvv.com%s">View</a>' % url109 view_on_site.allow_tags = True110@admin.register(ProductVariant)111class ProductVariantAdmin(SortableAdmin, ImportExportModelAdmin):112 actions = ['toggle_publish']113 list_display = (114 'publish',115 'parent_product',116 'product_variant',117 'inventory',118 'date',119 'image_img',120 'view_on_site',121 )122 list_editable = (123 'publish',124 'inventory',125 )126 list_display_links = (127 'parent_product',128 'product_variant',129 )130 inlines = [productImagesInline, productVideosInline]131 list_filter = ('product', 'publish')132 search_fields = (133 'name',134 'sku',135 )136 resource_class = ProductVariantResource137 def product_variant(self, obj):138 return obj.name139 def parent_product(self, obj):140 return obj.product.name141 def toggle_publish(self, request, queryset):142 queryset.update(publish=True)143 @mark_safe144 def view_on_site(self, obj):145 url = reverse(146 'product',147 kwargs={148 'category_name': obj.product.category.sku,149 'product_name': obj.product.sku,150 'variant_name': obj.sku151 })152 return '<a class="button" target="_blank" href="http://vvvvovvvv.com%s">View</a>' % url153 view_on_site.allow_tags = True154 parent_product.short_description = 'Product'155 product_variant.short_description = 'Variant'156@admin.register(Category)157class CategoryAdmin(SortableAdmin, ImportExportModelAdmin):158 actions = ['toggle_publish']159 list_display = (160 'publish',161 'name',162 'admin_description',163 'image_img',164 'view_on_site',165 )166 list_display_links = ('name', 'admin_description', 'image_img')167 list_editable = ('publish', )168 search_fields = ('name', )169 resource_class = CategoryResource170 inlines = [productInline]171 def toggle_publish(self, request, queryset):172 queryset.update(publish=True)173 @mark_safe174 def admin_description(self, obj):175 return '<div style="max-width:300px">%s<div>' % obj.description176 @mark_safe177 def view_on_site(self, obj):178 url = reverse('products', kwargs={'category_name': obj.sku})179 return '<a class="button" target="_blank" href="http://vvvvovvvv.com%s">View</a>' % url180 view_on_site.allow_tags = True181 admin_description.allow_tags = True182@admin.register(Store)183class StoreAdmin(SingletonModelAdmin):184 list_display = (185 'name',186 'small_description',187 'mail',188 'phone',...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

...15 (99, _(u'Outra')),16)17class Area(models.Model):18 description = tinymce_models.HTMLField(_(u'Descrição da página'))19 def admin_description(self):20 return self.description21 admin_description.allow_tags = True22 admin_description.short_description = _(u'Descrição da página')23 def __unicode__(self):24 return unicode(self.description)25 class Meta:26 verbose_name = _(u'Descrição da Página')27 verbose_name_plural = _(u'Descrição da Página')28 ordering = ['-id']29class Segment(models.Model):30 name = models.CharField(_(u'Nome do Segmento'), max_length=50, unique=True)31 def __unicode__(self):32 return unicode(self.name)33 @staticmethod34 def autocomplete_search_fields():35 return ("name__icontains",)36 class Meta:37 verbose_name = _(u'Segmento')38 verbose_name_plural = _(u'Segmentos')39 ordering = ['name']40class SellerAllManager(models.Manager):41 """42 Esse manager carrega todos os objetos do model Entry sem filtros43 """44 def get_queryset(self):45 return super(SellerAllManager,46 self).get_queryset().all()47class SellerPublishedManager(models.Manager):48 """49 Esse manager carrega todos os objetos do model Entry que estao marcados50 como publish=True51 """52 def get_queryset(self):53 return super(SellerPublishedManager,54 self).get_queryset().filter(visible=True)55class Seller(models.Model):56 area = models.ForeignKey(Area, verbose_name=_(u'Página'), blank=True,57 null=True, editable=False)58 name = models.CharField(_(u'Nome'), max_length=150, unique=True)59 state = models.CharField(_(u'UF'), max_length=2, choices=STATE_CHOICES)60 segment = models.ManyToManyField(Segment, verbose_name=_(u'Segmento'))61 visible = models.BooleanField(_(u'Visível no site?'), default=True)62 objects = SellerAllManager()63 published = SellerPublishedManager()64 def get_phone(self):65 out = []66 for k in Phone.objects.filter(seller=self.pk):67 out.append('%s [%s]<br>' % (k.number, k.get_operator_display()))68 return '\n'.join(out)69 get_phone.allow_tags = True70 get_phone.short_description = _(u'Fones')71 def get_email(self):72 out = []73 for k in Email.objects.filter(seller=self.pk):74 out.append('%s<br>' % k.address)75 return '\n'.join(out)76 get_email.allow_tags = True77 get_email.short_description = _(u'Emails')78 def save(self, *args, **kwargs):79 check = Area.objects.all().order_by('-pk')[:1]80 if not check:81 a = Area(description=u"Aguardando conteúdo...")82 a.save()83 self.area = a84 else:85 self.area = check[0]86 super(Seller, self).save(*args, **kwargs)87 def __unicode__(self):88 return unicode(self.name)89 class Meta:90 verbose_name = _(u'Vendedor')91 verbose_name_plural = _(u'Vendedores')92 ordering = ['name', 'state']93class Phone(models.Model):94 seller = models.ForeignKey('Seller', verbose_name=_(u'Vendedor'))95 operator = models.IntegerField(_(u'Operadora'), choices=OPERATOR_CHOICES)96 number = models.CharField(_(u'Número'), max_length=20,97 help_text='(99) 9999-9999')98 default = models.BooleanField(_(u'Número principal?'))99 @staticmethod100 def autocomplete_search_fields():101 return ("number__icontains", "operator__icontains",)102 def __unicode__(self):103 return unicode(self.number)104 class Meta:105 verbose_name = _(u'Fone')106 verbose_name_plural = _(u'Fones')107 ordering = ['-default']108class Email(models.Model):109 seller = models.ForeignKey('Seller', verbose_name=_(u'Vendedor'))110 address = models.EmailField(_(u'Endereço de email'))111 default = models.BooleanField(_(u'Email principal?'))112 @staticmethod113 def autocomplete_search_fields():114 return ("address__icontains",)115 def __unicode__(self):116 return unicode(self.address)117 class Meta:118 verbose_name = _(u'Email')119 verbose_name_plural = _(u'Emails')120 ordering = ['-default', 'address']121class Estimate(models.Model):122 created = models.DateTimeField(_(u'Data da Solicitação'),123 auto_now_add=True)124 segment = models.ForeignKey('Segment', verbose_name=_(u'Segmento'))125 enterprise = models.CharField(_(u'Empresa'), max_length=200)126 cnpj = models.CharField(_(u'CNPJ'), max_length=20,127 help_text='99.999.999/9999-99',128 blank=True, null=True)129 name = models.CharField(_(u'Nome'), max_length=200)130 address = models.CharField(_(u'Endereço'), max_length=200, blank=True,131 null=True)132 cep = models.CharField(_(u'CEP'), max_length=9, help_text='99999-999',133 blank=True, null=True)134 complement = models.CharField(_(u'Complemento'), max_length=100,135 blank=True, null=True)136 district = models.CharField(_(u'Bairro'), max_length=100,137 blank=True, null=True)138 city = models.CharField(_(u'Cidade'), max_length=100,139 blank=True, null=True)140 state = models.CharField(_(u'UF'), max_length=2, choices=STATE_CHOICES,141 blank=True, null=True)142 phone = models.CharField(_(u'Fone'), max_length=20,143 help_text='(99) 9999-9999')144 email = models.EmailField(_(u'Email'))145 message = tinymce_models.HTMLField(_(u'Mensagem'))146 def admin_description(self):147 return self.description148 admin_description.allow_tags = True149 admin_description.short_description = _(u'Mensagem')150 def __unicode__(self):151 return unicode(self.name)152 class Meta:153 verbose_name = _(u'Cotação')154 verbose_name_plural = _(u'Cotações')...

Full Screen

Full Screen

serializers.py

Source:serializers.py Github

copy

Full Screen

1from django.conf import settings2from django.contrib.auth import get_user_model3from rest_framework import serializers4from rest_framework.reverse import reverse5from .models import Post, Image, Category6User = get_user_model()7class CategorySerializer(serializers.ModelSerializer):8 class Meta:9 model = Category10 fields = [11 'title',12 'slug'13 ]14class ImageSerializer(serializers.HyperlinkedModelSerializer):15 owner = serializers.StringRelatedField()16 post = serializers.StringRelatedField()17 category = serializers.SlugRelatedField(18 slug_field='slug',19 queryset=Category.objects.all()20 )21 url = serializers.HyperlinkedIdentityField(22 view_name='post:image_user-detail')23 class Meta:24 model = Image25 fields = [26 'owner',27 'title',28 'owner_description',29 'admin_description',30 'category',31 'image',32 'post',33 'total_views',34 'url'35 ]36 37 read_only_fields = [38 'owner',39 'admin_description',40 'post',41 'total_views'42 ]43class ImagePublishedSerializer(serializers.ModelSerializer):44 category = serializers.SlugRelatedField(45 slug_field='slug',46 queryset=Category.objects.all()47 )48 class Meta:49 model = Image50 fields = [51 'title',52 'owner_description',53 'admin_description',54 'category',55 'image',56 'total_views',57 ]58 59 read_only_fields = [60 'admin_description',61 'total_views'62 ]63class PostSerializer(serializers.ModelSerializer):64 owner = serializers.StringRelatedField()65 images = ImagePublishedSerializer(many=True)66 class Meta:67 model = Post68 fields = [69 'owner',70 'title',71 'description',72 'images',73 'created',74 'updated'75 ]76 77 read_only_fields = [78 'owner',79 'created',80 'updated'81 ]82class PostManageSerializer(serializers.HyperlinkedModelSerializer):83 owner = serializers.StringRelatedField()84 url = serializers.HyperlinkedIdentityField(85 view_name='post:post_manage-detail')86 images = serializers.HyperlinkedRelatedField(87 many=True,88 read_only=True,89 view_name='post:image_manage-detail'90 )91 class Meta:92 model = Post93 fields = [94 'owner',95 'title',96 'description',97 'images',98 'is_active',99 'created',100 'updated',101 'url'102 ]103 104 read_only_fields = [105 'owner',106 'created',107 'updated'108 ]109class ImageManageSerializer(serializers.HyperlinkedModelSerializer):110 owner = serializers.StringRelatedField()111 post = serializers.SlugRelatedField(112 slug_field='pk',113 queryset=Post.objects.all()114 )115 category = serializers.SlugRelatedField(116 slug_field='slug',117 queryset=Category.objects.all()118 )119 url = serializers.HyperlinkedIdentityField(120 view_name='post:image_manage-detail')121 class Meta:122 model = Image123 fields = [124 'owner',125 'title',126 'owner_description',127 'admin_description',128 'category',129 'image',130 'created',131 'updated',132 'post',133 'total_views',134 'url'135 ]136 137 read_only_fields = [138 'owner',139 'total_views',140 'created',141 'updated',142 ]143 def to_representation(self, instance):144 """Convert `username` to lowercase."""145 ret = super().to_representation(instance)146 post_pk = ret['post']147 post = Post.objects.get(pk=post_pk)148 ret['post'] = str(post)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful