doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/python/DjangoOrmScanner.java [289:349]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            String primaryKey = null;

            for (PythonAst.Field field : pythonClass.fields()) {
                if (field.name().equals(META_CLASS_NAME) || field.name().startsWith("_")) {
                    continue;
                }

                // Check if this is a relationship field
                if (RELATIONSHIP_FIELDS.stream().anyMatch(rel -> field.type().contains(rel))) {
                    // Extract relationship
                    Relationship rel = extractRelationship(pythonClass.name(), field);
                    if (rel != null) {
                        relationships.add(rel);
                        log.debug("Found Django relationship: {} --[{}]--> {}",
                            pythonClass.name(), field.type(), rel.targetId());
                    }
                } else {
                    // Regular field
                    String sqlType = mapDjangoFieldToSql(field.type());
                    boolean nullable = isNullableField(field.value());
                    boolean isPrimaryKey = isPrimaryKeyField(field.value());

                    DataEntity.Field dataField = new DataEntity.Field(
                        field.name(),
                        sqlType,
                        nullable,
                        null
                    );

                    fields.add(dataField);

                    if (isPrimaryKey && primaryKey == null) {
                        primaryKey = field.name();
                    }

                    log.debug("Found Django field: {}.{} ({})", pythonClass.name(), field.name(), sqlType);
                }
            }

            // Django models always have an implicit 'id' primary key if not specified
            if (primaryKey == null) {
                primaryKey = DEFAULT_PRIMARY_KEY;
                DataEntity.Field idField = new DataEntity.Field(
                    DEFAULT_PRIMARY_KEY,
                    FIELD_AUTO,
                    false,
                    null
                );
                fields.add(0, idField);
            }

            // Create DataEntity
            if (!fields.isEmpty()) {
                DataEntity entity = new DataEntity(
                    pythonClass.name(),
                    tableName,
                    ENTITY_TYPE_TABLE,
                    fields,
                    primaryKey,
                    "Django Model: " + pythonClass.name()
                );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/python/DjangoOrmScanner.java [442:502]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            String primaryKey = null;

            for (PythonAst.Field field : pythonClass.fields()) {
                if (field.name().equals(META_CLASS_NAME) || field.name().startsWith("_")) {
                    continue;
                }

                // Check if this is a relationship field
                if (RELATIONSHIP_FIELDS.stream().anyMatch(rel -> field.type().contains(rel))) {
                    // Extract relationship
                    Relationship rel = extractRelationship(pythonClass.name(), field);
                    if (rel != null) {
                        relationships.add(rel);
                        log.debug("Found Django relationship: {} --[{}]--> {}",
                            pythonClass.name(), field.type(), rel.targetId());
                    }
                } else {
                    // Regular field
                    String sqlType = mapDjangoFieldToSql(field.type());
                    boolean nullable = isNullableField(field.value());
                    boolean isPrimaryKey = isPrimaryKeyField(field.value());

                    DataEntity.Field dataField = new DataEntity.Field(
                        field.name(),
                        sqlType,
                        nullable,
                        null
                    );

                    fields.add(dataField);

                    if (isPrimaryKey && primaryKey == null) {
                        primaryKey = field.name();
                    }

                    log.debug("Found Django field: {}.{} ({})", pythonClass.name(), field.name(), sqlType);
                }
            }

            // Django models always have an implicit 'id' primary key if not specified
            if (primaryKey == null) {
                primaryKey = DEFAULT_PRIMARY_KEY;
                DataEntity.Field idField = new DataEntity.Field(
                    DEFAULT_PRIMARY_KEY,
                    FIELD_AUTO,
                    false,
                    null
                );
                fields.add(0, idField);
            }

            // Create DataEntity
            if (!fields.isEmpty()) {
                DataEntity entity = new DataEntity(
                    pythonClass.name(),
                    tableName,
                    ENTITY_TYPE_TABLE,
                    fields,
                    primaryKey,
                    "Django Model: " + pythonClass.name()
                );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



