RuntimeError:应用程序“目录”中的'product_product_options'模型冲突

时间:2016-05-17 08:42:44

标签: django django-oscar

版本信息 Python 3.4,Django 1.8,Oscar Commerce - VERSION =(1,2,1,'final')

我正在尝试在documentation之后的目录应用中自定义Products

分配了catalogue应用后,我已将models.py定义如下:

from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractProduct

class Product(AbstractProduct):
    is_active = models.BooleanField(default=False)

from oscar.apps.catalogue.models import *

我已将已修改的目录包含在INSTALLED_APPS settings.py中的INSTALLED_APPS = INSTALLED_APPS + get_core_apps( ['app.gravytrain.catalogue',]) 列表中,与类似问题的建议here一样。

oscar/apps/catalogue

已将迁移文件夹从RuntimeError: Conflicting 'product_product_options' models in application 'catalogue': <class 'gravytrain.catalogue.models.Product_product_options'> and <class app.gravytrain.catalogue.models.Product_product_options'>. 复制到我的自定义应用。 但是,正在运行的迁移会导致以下错误:

// stacked contours
int main(int argc, char* argv[])
{
    cv::Mat input = cv::imread("C:/StackOverflow/Input/Contours_in_Contours.png");

    cv::Mat input_red = cv::imread("C:/StackOverflow/Input/Contours_in_Contours_RED.png");

    cv::Mat reds;
    cv::inRange(input_red, cv::Scalar(0, 0, 200), cv::Scalar(50, 50, 255), reds);
    std::vector<std::vector<cv::Point> > contours1;
    cv::findContours(reds, contours1, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    cv::Mat input_yellow = cv::imread("C:/StackOverflow/Input/Contours_in_Contours_YELLOW.png");

    cv::Mat yellows;
    cv::inRange(input, cv::Scalar(0, 200, 200), cv::Scalar(0, 255, 255), yellows);
    std::vector<std::vector<cv::Point> > contours2;
    cv::findContours(yellows, contours2, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    // now we have 2 sets of contours and want to find out whether contours of set2 are completely within a contour of contours1 without hierarchy information.

    std::vector<cv::Mat> masks1;
    std::vector<int> nMaskPixels1;
    // for each contour in contours1: create a contour mask:
    for (int i = 0; i < contours1.size(); ++i)
    {
        cv::Mat mask1 = cv::Mat::zeros(input.size(), CV_8UC1);
        cv::drawContours(mask1, contours1, i, cv::Scalar::all(255), -1); // draw filled
        int nPixel1 = cv::countNonZero(mask1);

        masks1.push_back(mask1);
        nMaskPixels1.push_back(nPixel1);
    }

    std::vector<cv::Mat> masks2;
    std::vector<int> nMaskPixels2;
    // for each contour in contours2: test whether it is completely within the reference contour:
    for (int j = 0; j < contours2.size(); ++j)
    {
        cv::Mat mask2 = cv::Mat::zeros(input.size(), CV_8UC1);
        cv::drawContours(mask2, contours2, j, cv::Scalar::all(255), -1); // draw filled
        int nPixel2 = cv::countNonZero(mask2);

        masks2.push_back(mask2);
        nMaskPixels2.push_back(nPixel2);
    }

    for (int i = 0; i < masks1.size(); ++i)
    {
        cv::Mat mask1 = masks1[i];

        // draw mask again for visualization:
        cv::Mat outIm = input.clone();
        cv::drawContours(outIm, contours1, i, cv::Scalar(0, 0, 0), 3);

        for (int j = 0; j < masks2.size(); ++j)
        {
            cv::Mat mask2 = masks2[j];

            cv::Mat overlap = mask1 & mask2;
            int nOverlapPixels = cv::countNonZero(overlap);
            if (nOverlapPixels == 0) continue; // no overlap at all. Test next contour.

            if (nOverlapPixels == nMaskPixels2[j] && nOverlapPixels < nMaskPixels1[i])
            {
                // second contour is completely within first contour
                cv::drawContours(outIm, contours2, j, cv::Scalar(0, 255, 0), 3);
            }
            else if (nOverlapPixels == nMaskPixels2[j] && nOverlapPixels == nMaskPixels1[i])
            {
                // both contours are identical
                std::cout << "WARNING: " << "contours " << i << " and " << j << " are identical" << std::endl;
            }
            else if (nOverlapPixels < nMaskPixels2[j] && nOverlapPixels == nMaskPixels1[i])
            {
                // first contour is completely within second contour
                std::cout << "WARNING: " << "contour " << i << " of the first set is inside of " << j << std::endl;
            }
            else if (nOverlapPixels < nMaskPixels2[j] && nOverlapPixels < nMaskPixels1[i])
            {
                // both contours intersect
                cv::drawContours(outIm, contours2, j, cv::Scalar(255, 0, 255), 3);
            }

        }

        cv::imshow("contours", outIm);
        cv::imwrite("C:/StackOverflow/Output/contours.png", outIm);
        cv::waitKey(0);

    }



    cv::imshow("input", input);
    cv::waitKey(0);
    return 0;
}

如何克服此错误?

2 个答案:

答案 0 :(得分:1)

如果要导入某些模型,则需要使用get_model函数。 例如:

from oscar.core.loading import get_model
Product = get_model('catalogue', 'Product')

答案 1 :(得分:0)

我有同样的错误。我还从oscar.apps.catalogue.models import *&#34;中包含了#34;在模型的顶部。一旦我被删除它,该问题已修复。