[Solved]-How do you parse and inject additional nodes in a Jinja extension?

7👍 ✅ templatetags/wrap.py class WrapExtension(jinja2.ext.Extension): tags = set([‘wrap’]) template = None def parse(self, parser): tag = parser.stream.current.value lineno = parser.stream.next().lineno args, kwargs = self.parse_args(parser) body = parser.parse_statements([‘name:end{}’.format(tag)], drop_needle=True) return nodes.CallBlock(self.call_method(‘wrap’, args, kwargs), [], [], body).set_lineno(lineno) def parse_args(self, parser): args = [] kwargs = [] require_comma = False while parser.stream.current.type != ‘block_end’: if require_comma: parser.stream.expect(‘comma’) if … Read more

[Solved]-Django Storages using s3boto ignoring MEDIA_URL

6👍 ✅ I struck the same issue when attempting to use the Imgix CDN for my S3 media (I suspect we’re both using the same tutorial based on your use of the custom_storages.py override). Here is an abridged version of the S3BotoStorage class in the django-storages framework. This excerpt highlights the important properties and methods … Read more

[Solved]-Django Rest Framework – return user id and token after registration

6👍 ✅ The mistake is in the line user = User.objects.filter(user=serializer.instance) Firstly, there is no field named user on your User model. Secondly, you don’t need to filter on the User model to get the created user as you already have the user with you in serializer.instance. So, there is no need for that line. … Read more

[Solved]-How to create factory-boy factories for Django models with the same foreign key

6👍 You can use the Params option (http://factoryboy.readthedocs.io/en/latest/reference.html#parameters): class RecordingFactory(factory.django.DjangoModelFactory): class Meta: model = models.Recording class Params: language = factory.SubFactory(Language) subtitles = factory.SubFactory(SubtitlesFactory, language=factory.SelfAttribute(‘language’)) audio = factory.SubFactory(AudioFactory, language=factory.SelfAttribute(‘language’)) 👤Xelnor QuerySet is not JSON Serializable Django 1👍 Possible solution is to generate the shared foreign key model, assign it to each subfactory, and then remove it … Read more

[Solved]-DJango REST Framework Read Only field

6👍 You could create a different model serializer for each use case (update, create): specifying that field in read_only_fields in your model serializer: class MyModelSerializer(serializers.ModelSerializer): class Meta: model = MyModel fields = (‘a’, ‘nother’, ‘field’) read_only_fields = (‘owner’,) for django forms instead you set the disabled field: class MyModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) … Read more

[Solved]-How to access Postgres database within docker-compose

7👍 ✅ To access postgres in the container, run the cli in the scope of the container docker-compose run postgres psql You can also connect to the containers published port, which hasn’t been published in your existing config. postgres: build: context: . dockerfile: ./compose/production/postgres/Dockerfile volumes: – postgres_data_local:/var/lib/postgresql/data – postgres_backup_local:/backups ports: – ‘5433:5432’ environment: – POSTGRES_USER=vicki … Read more

[Solved]-JSONField workaround on elasticsearch : MapperParsingException

7👍 If the method mentioned in the link you posted works (I haven’t tested it on JSONField), then you’re overriding the wrong method: The method the elasticsearch app uses to prep the field is prepare_FOO where FOO is the field name. So you need to call your method prepare_web_results() instead of prepare_content_json() since your field … Read more