These are chat archives for django/django

Jun 2018
Curtis Maloney
Jun 29 2018 00:16 UTC
@manjitkumar what happened when you tried?
Jun 29 2018 08:51 UTC

Hy all !
I'm runnig in a anoying issue
in my Dockerfile i do

ADD /config/conf.yaml /src/ 
RUN ls -l /src/

on build it outputs

Step 8/13 : ADD /config/conf.yaml /src/
 ---> Using cache
 ---> edbd4e1ca39c
Step 11/13 : RUN ls -l /src/
 ---> Running in 0c5e93062785
total 28
drwxrwxr-x 6 root root 4096 Jun 28 09:16 api
-rw-rw-r-- 1 root root  123 Jun 28 09:00 conf.yaml
drwxrwxr-x 4 root root 4096 Jun 28 09:16 core
drwxrwxr-x 3 root root 4096 Jun 28 09:16 docs
drwxrwxr-x 6 root root 4096 Jun 28 09:16 frontend
-rwxrwxr-x 1 root root  536 Jun 27 13:16
drwxrwxr-x 2 root root 4096 Jun 28 14:36 poc2

BUT on up i get

dg01     | ERROR - 2018-06-29 10:27:18,697 - api.lib.consent <module> - No configuration file                                        
dg01     | ERROR - 2018-06-29 10:27:18,697 - api.lib.consent <module> - "/src/conf.yaml"                                             
dg01     | ERROR - 2018-06-29 10:27:18,698 - api.lib.consent <module> - exception

wich is a response from that consent module

    stream = open(os.environ['ENV_YAML_CONF'], "r")
    logger.error('No configuration file')
keys = yaml.load(stream)
I've tried src.conf.yaml mith quote, double quotes, no quotes... I don't understand.
Curtis Maloney
Jun 29 2018 08:59 UTC
@LukeVideo are you sure it didn't put it in /src/conf/config.yaml ?
Jun 29 2018 09:02 UTC
Yep it's looged out as "/src/conf.yaml" in the console. so i guess os.environ['ENV_YAML_CONF'] is properly understood in the try statement... It all worked fine before i tried to Dockerize it...
Curtis Maloney
Jun 29 2018 09:03 UTC
what user does your task run as?
so, yeah, firstly... remove the quotes...
Jun 29 2018 09:11 UTC
I guess i'm root. I'll check again. But see the rest works out so i wonder how a user could start the project as all is owned by root anyway. But yeah i'll check again :smile:
ok, quotes gone !
let it build again and i'll let you know
Jun 29 2018 09:21 UTC
Error gone ! Now i get
django.db.utils.OperationalError: could not translate host name "'db'" to address: Name or service not known
I'm guessing i should get rid of quotes !
Jun 29 2018 09:28 UTC
Hooray !
Curtis Maloney
Jun 29 2018 09:33 UTC
Jun 29 2018 10:01 UTC
Ok so now ... the db wich is a postgres image doesn't have the db described in the .env file. Should i rm the image and start again ?
Curtis Maloney
Jun 29 2018 10:02 UTC
can't help you there, mate...
Jun 29 2018 10:04 UTC
i'll just give it a try anyway. It's just that it takes forever to rebuild my image for the web container... pip install django on a crappy connection isn't the best... And all the rest :laughing:
Jun 29 2018 13:45 UTC
How do i use rest framework APIView to post the product in the cart ?
class CartAPI(APIView):
    serializer_class = serializers.CartSerializer

    def get(self, request, format=None):
        reply = {}
            carts = Cart.objects.all()
            reply['data'] = self.serializer_class(carts, many=True).data
        except Cart.DoesNotExist:
            reply['data'] = []
        return Response(reply, status.HTTP_200_OK)

    def post(self, request, format=None):
        reply = {}
        cart = Cart(request)
        product_id ='product', None)
        quantity ='quantity', None)
            product = Variation.objects.get(id=product_id)
        except Variation.DoesNotExist:
        isProductInCart = False
        for cart_item in cart:
            if ==
                cart_item.quantity = quantity
                isProductInCart = True
        if not isProductInCart:
            # create and save new item in the cart
            cart_product = CartItem.objects.create(cart=cart)
            cart_product.item = product
            cart_product.quantity = quantity
            reply['data'] = self.serializer_class(cart_product,
        return Response(reply, status.HTTP_200_OK)

class Cart(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now_add=False, auto_now=True)
    subtotal = models.DecimalField(max_digits=50, decimal_places=2, default=0.00)
    total = models.DecimalField(max_digits=50, decimal_places=2, default=0.00)

class CartItem(models.Model):
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    item = models.ForeignKey(Variation, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    line_item_total = models.DecimalField(max_digits=10, decimal_places=2)

class CartSerializer(serializers.ModelSerializer):
    item = VariationSerializer(many=True, read_only=True)

    class Meta:
        model = Cart
        fields = ('item', 'user', 'timestamp', 'updated', 'subtotal', 'total', 'active',)

class CartItemSerializer(serializers.ModelSerializer):

    class Meta:
        model = CartItem
        fields = '__all__'
can anyone help me at this, please?
I am happy to share the repo either
Patrick Jury
Jun 29 2018 15:40 UTC
Can anyone point me at the best way to write a Django view that returns all objects with specific foreign key
Jun 29 2018 18:21 UTC
@MilanRgm You do it wrong way
  1. Use ModelViewSet
  2. Use Nested Serializer because you will get major advantages from validators
Jun 29 2018 23:02 UTC
hi guys
I 'm with problems with django -filter
someone work django filters?