Carbon0-Games/carbon0-web-app

zeron_image_url does not display on the Achievement tab of the Admin site.

UPstartDeveloper opened this issue · 0 comments

Hey team,

So there's an error with the zeron_image_url field not having a value, when you look at any of the Achievement models from the Admin.

However, the actual value of this field is being set correctly, since the Zerons do appear on the AchievementDetail view.

So far what I've gathered is that this field, zeron_image_url is set in the AchievementCreate.form_valid method, in the carbon_quiz.views module, using the following line:

# set the url of the Zeron image field
form.instance.zeron_image_url = Achievement.set_zeron_image_url(mission)

The method that is being called, Achievement.set_zeron_image_url is implemented as follows:

    @classmethod
    def set_zeron_image_url(cls, mission):
        """
        Returns the appropiate Zeron, given a Mission model instance.

        Parameters:
        mission(Mission): the Mission model that has been completed

        Returns:
        Tuple(str, str): the value in Achievement.ZERONS that
                         corresponds to the category this Mission
                         falls under (must refer back to related Question)

        """
        # get the category of the question related to the mission
        category = mission.question.category
        # store a list of the categories Questions may be in
        category_abbreviations = [
            category_abbrev for category_abbrev, category in Question.CATEGORIES
        ]
        # map each category to a Zeron name
        category_to_zerons = dict(zip(category_abbreviations, Achievement.ZERONS))
        # find the right choice of zeron, given the category
        zeron_img_paths, zeron_model_name = category_to_zerons[category]
        return zeron_img_paths

And the field itself is as follows:

 # Zerons for Achievements: (img_url_paths: List[str], name_of_zeron: str)
    ZERONS = [
        # 1. Diet category Zeron
        (settings.DIET_ZERON_PATHS, "Nature's Model"),
        # 2. Transit category Zeron
        (settings.TRANSIT_ZERON_PATHS, "Wheel Model"),
        # 3. Recycling category Zeron
        (settings.RECYCLING_ZERON_PATHS, "Bin Model"),
        # 4. Airline-Travel category Zeron
        (settings.AT_ZERON_PATHS, "Coin Model"),
        # 5. Utilities category Zeron
        (settings.UTIL_ZERON_PATHS, "Light Bulb Model"),
    ]
    zeron_image_url = ArrayField(
        models.CharField(
            max_length=100,
            null=True,
            blank=True,
        ),
        null=True,
        blank=True,
        choices=ZERONS,
        help_text="File paths to the 3D model in storage.",
    )

Could anyone help us understand why this is occurring?

For reference, here's the Model Field Reference page from the Django docs.