您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.conf import settings
  2. from django.core.files.images import ImageFile
  3. from django_images.models import Thumbnail
  4. from taggit.models import Tag
  5. from core.models import Pin, Image
  6. from users.models import User
  7. TEST_IMAGE_PATH = 'logo.png'
  8. def create_user(username):
  9. user, _ = User.objects.get_or_create(
  10. username='user_{}'.format(username),
  11. defaults={
  12. "email": 'user_{}@example.com'.format(username)
  13. }
  14. )
  15. user.set_password("password")
  16. user.save()
  17. return user
  18. def create_tag(name):
  19. return Tag.objects.get_or_create(
  20. name='tag_{}'.format(name),
  21. slug='tag_{}'.format(name),
  22. )
  23. def create_image():
  24. image = Image.objects.create(image=ImageFile(open(TEST_IMAGE_PATH, 'rb')))
  25. for size in settings.IMAGE_SIZES.keys():
  26. Thumbnail.objects.get_or_create_at_size(image.pk, size)
  27. return image
  28. def create_pin(user, image, tags):
  29. pin = Pin.objects.create(submitter=user, image=image)
  30. pin.tags.set(*tags)
  31. return pin